Commit 7a0308de authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Move the caption color handling code from WindowStateDelegate to CustomFrameViewAsh.

A client may set custom WindowStateDelegate, so the code should be
in the CustomFrameViewAsh.

BUG=33693796
TEST=covered by unit tests.

Change-Id: Iccacddf8a0bce01ed1a3819c959e73d591a8d8ef
Reviewed-on: https://chromium-review.googlesource.com/972677
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545092}
parent 33b84dc5
...@@ -114,10 +114,7 @@ const char FrameCaptionButtonContainerView::kViewClassName[] = ...@@ -114,10 +114,7 @@ const char FrameCaptionButtonContainerView::kViewClassName[] =
FrameCaptionButtonContainerView::FrameCaptionButtonContainerView( FrameCaptionButtonContainerView::FrameCaptionButtonContainerView(
views::Widget* frame) views::Widget* frame)
: frame_(frame), : frame_(frame) {
minimize_button_(NULL),
size_button_(NULL),
close_button_(NULL) {
constexpr int kTouchOptimizedCaptionButtonsSpacing = 8; constexpr int kTouchOptimizedCaptionButtonsSpacing = 8;
auto layout = std::make_unique<views::BoxLayout>( auto layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, gfx::Insets(), views::BoxLayout::kHorizontal, gfx::Insets(),
......
...@@ -138,9 +138,9 @@ class ASH_EXPORT FrameCaptionButtonContainerView ...@@ -138,9 +138,9 @@ class ASH_EXPORT FrameCaptionButtonContainerView
// The buttons. In the normal button style, at most one of |minimize_button_| // The buttons. In the normal button style, at most one of |minimize_button_|
// and |size_button_| is visible. // and |size_button_| is visible.
FrameCaptionButton* minimize_button_; FrameCaptionButton* minimize_button_ = nullptr;
FrameCaptionButton* size_button_; FrameCaptionButton* size_button_ = nullptr;
FrameCaptionButton* close_button_; FrameCaptionButton* close_button_ = nullptr;
// Mapping of the image needed to paint a button for each of the values of // Mapping of the image needed to paint a button for each of the values of
// CaptionButtonIcon. // CaptionButtonIcon.
......
...@@ -53,9 +53,8 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -53,9 +53,8 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
public: public:
CustomFrameViewAshWindowStateDelegate(wm::WindowState* window_state, CustomFrameViewAshWindowStateDelegate(wm::WindowState* window_state,
CustomFrameViewAsh* custom_frame_view, CustomFrameViewAsh* custom_frame_view,
HeaderView* header_view,
bool enable_immersive) bool enable_immersive)
: window_state_(nullptr), header_view_(header_view) { : window_state_(nullptr) {
// Add a window state observer to exit fullscreen properly in case // Add a window state observer to exit fullscreen properly in case
// fullscreen is exited without going through // fullscreen is exited without going through
// WindowState::ToggleFullscreen(). This is the case when exiting // WindowState::ToggleFullscreen(). This is the case when exiting
...@@ -130,26 +129,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -130,26 +129,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
window_state_ = nullptr; window_state_ = nullptr;
} }
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override {
DCHECK_EQ(window_state_->window(), window);
if (key != ash::kFrameActiveColorKey &&
key != ash::kFrameInactiveColorKey) {
return;
}
if (key == ash::kFrameActiveColorKey) {
header_view_->SetFrameColors(
window->GetProperty(ash::kFrameActiveColorKey),
header_view_->GetInactiveFrameColor());
return;
}
header_view_->SetFrameColors(
header_view_->GetActiveFrameColor(),
window->GetProperty(ash::kFrameInactiveColorKey));
}
// wm::WindowStateObserver: // wm::WindowStateObserver:
void OnPostWindowStateTypeChange(wm::WindowState* window_state, void OnPostWindowStateTypeChange(wm::WindowState* window_state,
mojom::WindowStateType old_type) override { mojom::WindowStateType old_type) override {
...@@ -179,7 +158,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -179,7 +158,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
} }
wm::WindowState* window_state_; wm::WindowState* window_state_;
HeaderView* const header_view_;
std::unique_ptr<ImmersiveFullscreenController> std::unique_ptr<ImmersiveFullscreenController>
immersive_fullscreen_controller_; immersive_fullscreen_controller_;
...@@ -342,13 +320,15 @@ CustomFrameViewAsh::CustomFrameViewAsh( ...@@ -342,13 +320,15 @@ CustomFrameViewAsh::CustomFrameViewAsh(
header_view_->GetActiveFrameColor()); header_view_->GetActiveFrameColor());
frame_window->SetProperty(ash::kFrameInactiveColorKey, frame_window->SetProperty(ash::kFrameInactiveColorKey,
header_view_->GetInactiveFrameColor()); header_view_->GetInactiveFrameColor());
frame_window->AddObserver(this);
// A delegate for a more complex way of fullscreening the window may already // A delegate for a more complex way of fullscreening the window may already
// be set. This is the case for packaged apps. // be set. This is the case for packaged apps.
wm::WindowState* window_state = wm::GetWindowState(frame_window); wm::WindowState* window_state = wm::GetWindowState(frame_window);
if (!window_state->HasDelegate()) { if (!window_state->HasDelegate()) {
window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>( window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>(
new CustomFrameViewAshWindowStateDelegate( new CustomFrameViewAshWindowStateDelegate(window_state, this,
window_state, this, header_view_, enable_immersive))); enable_immersive)));
} }
Shell::Get()->AddShellObserver(this); Shell::Get()->AddShellObserver(this);
Shell::Get()->split_view_controller()->AddObserver(this); Shell::Get()->split_view_controller()->AddObserver(this);
...@@ -358,6 +338,10 @@ CustomFrameViewAsh::~CustomFrameViewAsh() { ...@@ -358,6 +338,10 @@ CustomFrameViewAsh::~CustomFrameViewAsh() {
Shell::Get()->RemoveShellObserver(this); Shell::Get()->RemoveShellObserver(this);
if (Shell::Get()->split_view_controller()) if (Shell::Get()->split_view_controller())
Shell::Get()->split_view_controller()->RemoveObserver(this); Shell::Get()->split_view_controller()->RemoveObserver(this);
if (frame_ && frame_->GetNativeWindow() &&
frame_->GetNativeWindow()->HasObserver(this)) {
frame_->GetNativeWindow()->RemoveObserver(this);
}
} }
void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
...@@ -370,12 +354,9 @@ void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, ...@@ -370,12 +354,9 @@ void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color,
SkColor inactive_frame_color) { SkColor inactive_frame_color) {
header_view_->SetFrameColors(active_frame_color, inactive_frame_color); header_view_->SetFrameColors(active_frame_color, inactive_frame_color);
aura::Window* frame_window = frame_->GetNativeWindow(); aura::Window* frame_window = frame_->GetNativeWindow();
frame_window->SetProperty(aura::client::kTopViewColor, frame_window->SetProperty(aura::client::kTopViewColor, inactive_frame_color);
header_view_->GetInactiveFrameColor()); frame_window->SetProperty(ash::kFrameActiveColorKey, active_frame_color);
frame_window->SetProperty(ash::kFrameActiveColorKey, frame_window->SetProperty(ash::kFrameInactiveColorKey, inactive_frame_color);
header_view_->GetActiveFrameColor());
frame_window->SetProperty(ash::kFrameInactiveColorKey,
header_view_->GetInactiveFrameColor());
} }
void CustomFrameViewAsh::SetBackButtonState(FrameBackButtonState state) { void CustomFrameViewAsh::SetBackButtonState(FrameBackButtonState state) {
...@@ -434,7 +415,6 @@ void CustomFrameViewAsh::SizeConstraintsChanged() { ...@@ -434,7 +415,6 @@ void CustomFrameViewAsh::SizeConstraintsChanged() {
void CustomFrameViewAsh::ActivationChanged(bool active) { void CustomFrameViewAsh::ActivationChanged(bool active) {
// The icons differ between active and inactive. // The icons differ between active and inactive.
header_view_->SchedulePaint(); header_view_->SchedulePaint();
frame_->non_client_view()->Layout(); frame_->non_client_view()->Layout();
} }
...@@ -511,6 +491,28 @@ void CustomFrameViewAsh::SetVisible(bool visible) { ...@@ -511,6 +491,28 @@ void CustomFrameViewAsh::SetVisible(bool visible) {
InvalidateLayout(); InvalidateLayout();
} }
void CustomFrameViewAsh::OnWindowDestroying(aura::Window* window) {
DCHECK_EQ(frame_->GetNativeWindow(), window);
window->RemoveObserver(this);
}
void CustomFrameViewAsh::OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) {
DCHECK_EQ(frame_->GetNativeWindow(), window);
if (key != ash::kFrameActiveColorKey && key != ash::kFrameInactiveColorKey)
return;
if (key == ash::kFrameActiveColorKey) {
header_view_->SetFrameColors(window->GetProperty(ash::kFrameActiveColorKey),
header_view_->GetInactiveFrameColor());
return;
}
header_view_->SetFrameColors(
header_view_->GetActiveFrameColor(),
window->GetProperty(ash::kFrameInactiveColorKey));
}
const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
return header_view_->avatar_icon(); return header_view_->avatar_icon();
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window_observer.h"
#include "ui/views/window/non_client_view.h" #include "ui/views/window/non_client_view.h"
namespace views { namespace views {
...@@ -41,7 +42,8 @@ enum class FrameBackButtonState { ...@@ -41,7 +42,8 @@ enum class FrameBackButtonState {
// BrowserNonClientFrameViewAsh. // BrowserNonClientFrameViewAsh.
class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView, class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
public ShellObserver, public ShellObserver,
public SplitViewController::Observer { public SplitViewController::Observer,
public aura::WindowObserver {
public: public:
// Internal class name. // Internal class name.
static const char kViewClassName[]; static const char kViewClassName[];
...@@ -102,6 +104,12 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView, ...@@ -102,6 +104,12 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
void SchedulePaintInRect(const gfx::Rect& r) override; void SchedulePaintInRect(const gfx::Rect& r) override;
void SetVisible(bool visible) override; void SetVisible(bool visible) override;
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
void OnWindowPropertyChanged(aura::Window* window,
const void* key,
intptr_t old) override;
// If |paint| is false, we should not paint the header. Used for overview mode // If |paint| is false, we should not paint the header. Used for overview mode
// with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the // with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the
// header of v2 and ARC apps. // header of v2 and ARC apps.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/wm_event.h" #include "ash/wm/wm_event.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h" #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
...@@ -499,10 +500,47 @@ TEST_F(CustomFrameViewAshTest, FrameVisibility) { ...@@ -499,10 +500,47 @@ TEST_F(CustomFrameViewAshTest, FrameVisibility) {
EXPECT_TRUE(widget->non_client_view()->frame_view()->visible()); EXPECT_TRUE(widget->non_client_view()->frame_view()->visible());
} }
namespace {
class CustomFrameViewAshFrameColorTest
: public CustomFrameViewAshTest,
public testing::WithParamInterface<bool> {
public:
CustomFrameViewAshFrameColorTest() = default;
~CustomFrameViewAshFrameColorTest() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshFrameColorTest);
};
class TestWidgetDelegate : public TestWidgetConstraintsDelegate {
public:
TestWidgetDelegate(bool custom) : custom_(custom) {}
~TestWidgetDelegate() override = default;
// views::WidgetDelegate:
views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override {
if (custom_) {
ash::wm::WindowState* window_state =
ash::wm::GetWindowState(widget->GetNativeWindow());
window_state->SetDelegate(std::make_unique<wm::WindowStateDelegate>());
}
return TestWidgetConstraintsDelegate::CreateNonClientFrameView(widget);
}
private:
bool custom_;
DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
};
} // namespace
// Verify that CustomFrameViewAsh updates the active color based on the // Verify that CustomFrameViewAsh updates the active color based on the
// ash::kFrameActiveColorKey window property. // ash::kFrameActiveColorKey window property.
TEST_F(CustomFrameViewAshTest, kFrameActiveColorKey) { TEST_P(CustomFrameViewAshFrameColorTest, kFrameActiveColorKey) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; TestWidgetDelegate* delegate = new TestWidgetDelegate(GetParam());
std::unique_ptr<views::Widget> widget(CreateWidget(delegate)); std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
SkColor active_color = SkColor active_color =
...@@ -520,8 +558,8 @@ TEST_F(CustomFrameViewAshTest, kFrameActiveColorKey) { ...@@ -520,8 +558,8 @@ TEST_F(CustomFrameViewAshTest, kFrameActiveColorKey) {
// Verify that CustomFrameViewAsh updates the inactive color based on the // Verify that CustomFrameViewAsh updates the inactive color based on the
// ash::kFrameInactiveColorKey window property. // ash::kFrameInactiveColorKey window property.
TEST_F(CustomFrameViewAshTest, KFrameInactiveColor) { TEST_P(CustomFrameViewAshFrameColorTest, KFrameInactiveColor) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; TestWidgetDelegate* delegate = new TestWidgetDelegate(GetParam());
std::unique_ptr<views::Widget> widget(CreateWidget(delegate)); std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
SkColor active_color = SkColor active_color =
...@@ -538,4 +576,7 @@ TEST_F(CustomFrameViewAshTest, KFrameInactiveColor) { ...@@ -538,4 +576,7 @@ TEST_F(CustomFrameViewAshTest, KFrameInactiveColor) {
delegate->custom_frame_view()->GetInactiveFrameColorForTest()); delegate->custom_frame_view()->GetInactiveFrameColorForTest());
} }
// Run frame color tests with and without custom wm::WindowStateDelegate.
INSTANTIATE_TEST_CASE_P(, CustomFrameViewAshFrameColorTest, testing::Bool());
} // namespace ash } // namespace ash
...@@ -306,6 +306,13 @@ void DefaultFrameHeader::PaintHeaderContentSeparator(gfx::Canvas* canvas) { ...@@ -306,6 +306,13 @@ void DefaultFrameHeader::PaintHeaderContentSeparator(gfx::Canvas* canvas) {
void DefaultFrameHeader::UpdateAllButtonImages() { void DefaultFrameHeader::UpdateAllButtonImages() {
caption_button_container_->SetUseLightImages(ShouldUseLightImages()); caption_button_container_->SetUseLightImages(ShouldUseLightImages());
if (back_button_) {
back_button_->set_use_light_images(ShouldUseLightImages());
back_button_->SetImage(CAPTION_BUTTON_ICON_BACK,
FrameCaptionButton::ANIMATE_NO,
kWindowControlBackIcon);
}
caption_button_container_->SetButtonImage(CAPTION_BUTTON_ICON_MINIMIZE, caption_button_container_->SetButtonImage(CAPTION_BUTTON_ICON_MINIMIZE,
kWindowControlMinimizeIcon); kWindowControlMinimizeIcon);
......
...@@ -194,6 +194,8 @@ void HeaderView::SetShouldPaintHeader(bool paint) { ...@@ -194,6 +194,8 @@ void HeaderView::SetShouldPaintHeader(bool paint) {
void HeaderView::OnImmersiveRevealStarted() { void HeaderView::OnImmersiveRevealStarted() {
fullscreen_visible_fraction_ = 0; fullscreen_visible_fraction_ = 0;
SetPaintToLayer(); SetPaintToLayer();
// The immersive layer should always be top.
layer()->parent()->StackAtTop(layer());
parent()->Layout(); parent()->Layout();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment