Commit 8e446b43 authored by wutao's avatar wutao Committed by Commit Bot

cros: Allow client to set custom_frame_view color.

This cl allows client to set custom_frame_view color.
Changes:
1. Add OnWindowPropertyChanged to CustomFrameViewAshWindowStateDelegate.
2. Client can set custom_frame_view color by setting window property
aura::client::kTopViewColor.

Bug: 811159, 768932
Test: CustomFrameViewAshTest.KTopViewColor and manually test color update.
Change-Id: Ic2306c399b0d4cda88ffb0f96c48a15e3e6f430b
Reviewed-on: https://chromium-review.googlesource.com/912518
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarMitsuru Oshima (In Tokyo) <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536748}
parent 8343f15c
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/frame/header_view.h" #include "ash/frame/header_view.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller.h" #include "ash/public/cpp/immersive/immersive_fullscreen_controller.h"
#include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h" #include "ash/public/cpp/immersive/immersive_fullscreen_controller_delegate.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/resize_handle_window_targeter.h" #include "ash/wm/resize_handle_window_targeter.h"
...@@ -52,8 +53,9 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -52,8 +53,9 @@ 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) { : window_state_(nullptr), header_view_(header_view) {
// 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
...@@ -128,6 +130,26 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -128,6 +130,26 @@ 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 {
...@@ -157,6 +179,7 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -157,6 +179,7 @@ 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_;
...@@ -315,14 +338,17 @@ CustomFrameViewAsh::CustomFrameViewAsh( ...@@ -315,14 +338,17 @@ CustomFrameViewAsh::CustomFrameViewAsh(
frame->non_client_view()->SetOverlayView(overlay_view_); frame->non_client_view()->SetOverlayView(overlay_view_);
frame_window->SetProperty(aura::client::kTopViewColor, frame_window->SetProperty(aura::client::kTopViewColor,
header_view_->GetInactiveFrameColor()); header_view_->GetInactiveFrameColor());
frame_window->SetProperty(ash::kFrameActiveColorKey,
header_view_->GetActiveFrameColor());
frame_window->SetProperty(ash::kFrameInactiveColorKey,
header_view_->GetInactiveFrameColor());
// 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(window_state, this, new CustomFrameViewAshWindowStateDelegate(
enable_immersive))); window_state, this, header_view_, enable_immersive)));
} }
Shell::Get()->AddShellObserver(this); Shell::Get()->AddShellObserver(this);
Shell::Get()->split_view_controller()->AddObserver(this); Shell::Get()->split_view_controller()->AddObserver(this);
...@@ -346,6 +372,10 @@ void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, ...@@ -346,6 +372,10 @@ void CustomFrameViewAsh::SetFrameColors(SkColor active_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,
header_view_->GetInactiveFrameColor()); header_view_->GetInactiveFrameColor());
frame_window->SetProperty(ash::kFrameActiveColorKey,
header_view_->GetActiveFrameColor());
frame_window->SetProperty(ash::kFrameInactiveColorKey,
header_view_->GetInactiveFrameColor());
} }
void CustomFrameViewAsh::SetBackButtonState(FrameBackButtonState state) { void CustomFrameViewAsh::SetBackButtonState(FrameBackButtonState state) {
...@@ -485,6 +515,14 @@ const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const { ...@@ -485,6 +515,14 @@ const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
return header_view_->avatar_icon(); return header_view_->avatar_icon();
} }
SkColor CustomFrameViewAsh::GetActiveFrameColorForTest() const {
return header_view_->GetActiveFrameColor();
}
SkColor CustomFrameViewAsh::GetInactiveFrameColorForTest() const {
return header_view_->GetInactiveFrameColor();
}
void CustomFrameViewAsh::MaybePaintHeaderForSplitview( void CustomFrameViewAsh::MaybePaintHeaderForSplitview(
SplitViewController::State state) { SplitViewController::State state) {
if (state == SplitViewController::NO_SNAP) { if (state == SplitViewController::NO_SNAP) {
......
...@@ -122,6 +122,9 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView, ...@@ -122,6 +122,9 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
const views::View* GetAvatarIconViewForTest() const; const views::View* GetAvatarIconViewForTest() const;
SkColor GetActiveFrameColorForTest() const;
SkColor GetInactiveFrameColorForTest() const;
private: private:
class AvatarObserver; class AvatarObserver;
class OverlayView; class OverlayView;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "ash/frame/caption_buttons/frame_caption_button.h" #include "ash/frame/caption_buttons/frame_caption_button.h"
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h" #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/frame/header_view.h" #include "ash/frame/header_view.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/overview/window_selector_controller.h"
...@@ -498,4 +499,43 @@ TEST_F(CustomFrameViewAshTest, FrameVisibility) { ...@@ -498,4 +499,43 @@ TEST_F(CustomFrameViewAshTest, FrameVisibility) {
EXPECT_TRUE(widget->non_client_view()->frame_view()->visible()); EXPECT_TRUE(widget->non_client_view()->frame_view()->visible());
} }
// Verify that CustomFrameViewAsh updates the active color based on the
// ash::kFrameActiveColorKey window property.
TEST_F(CustomFrameViewAshTest, kFrameActiveColorKey) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
SkColor active_color =
widget->GetNativeWindow()->GetProperty(ash::kFrameActiveColorKey);
constexpr SkColor new_color = SK_ColorWHITE;
EXPECT_NE(active_color, new_color);
widget->GetNativeWindow()->SetProperty(ash::kFrameActiveColorKey, new_color);
active_color =
widget->GetNativeWindow()->GetProperty(ash::kFrameActiveColorKey);
EXPECT_EQ(active_color, new_color);
EXPECT_EQ(new_color,
delegate->custom_frame_view()->GetActiveFrameColorForTest());
}
// Verify that CustomFrameViewAsh updates the inactive color based on the
// ash::kFrameInactiveColorKey window property.
TEST_F(CustomFrameViewAshTest, KFrameInactiveColor) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
SkColor active_color =
widget->GetNativeWindow()->GetProperty(ash::kFrameInactiveColorKey);
constexpr SkColor new_color = SK_ColorWHITE;
EXPECT_NE(active_color, new_color);
widget->GetNativeWindow()->SetProperty(ash::kFrameInactiveColorKey,
new_color);
active_color =
widget->GetNativeWindow()->GetProperty(ash::kFrameInactiveColorKey);
EXPECT_EQ(active_color, new_color);
EXPECT_EQ(new_color,
delegate->custom_frame_view()->GetInactiveFrameColorForTest());
}
} // namespace ash } // namespace ash
...@@ -216,8 +216,17 @@ void DefaultFrameHeader::SetPaintAsActive(bool paint_as_active) { ...@@ -216,8 +216,17 @@ void DefaultFrameHeader::SetPaintAsActive(bool paint_as_active) {
void DefaultFrameHeader::SetFrameColors(SkColor active_frame_color, void DefaultFrameHeader::SetFrameColors(SkColor active_frame_color,
SkColor inactive_frame_color) { SkColor inactive_frame_color) {
bool updated = false;
if (active_frame_color_ != active_frame_color) {
active_frame_color_ = active_frame_color; active_frame_color_ = active_frame_color;
updated = true;
}
if (inactive_frame_color_ != inactive_frame_color) {
inactive_frame_color_ = inactive_frame_color; inactive_frame_color_ = inactive_frame_color;
updated = true;
}
if (updated)
UpdateAllButtonImages(); UpdateAllButtonImages();
} }
......
...@@ -21,6 +21,12 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kPanelAttachedKey, true); ...@@ -21,6 +21,12 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kPanelAttachedKey, true);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kShelfIDKey, nullptr); DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(std::string, kShelfIDKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kShelfItemTypeKey, TYPE_UNDEFINED); DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kShelfItemTypeKey, TYPE_UNDEFINED);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kShowInOverviewKey, true); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kShowInOverviewKey, true);
DEFINE_UI_CLASS_PROPERTY_KEY(SkColor,
kFrameActiveColorKey,
SK_ColorTRANSPARENT);
DEFINE_UI_CLASS_PROPERTY_KEY(SkColor,
kFrameInactiveColorKey,
SK_ColorTRANSPARENT);
DEFINE_UI_CLASS_PROPERTY_KEY(mojom::WindowPinType, DEFINE_UI_CLASS_PROPERTY_KEY(mojom::WindowPinType,
kWindowPinTypeKey, kWindowPinTypeKey,
mojom::WindowPinType::NONE); mojom::WindowPinType::NONE);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include "ash/public/cpp/ash_public_export.h" #include "ash/public/cpp/ash_public_export.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/class_property.h" #include "ui/base/class_property.h"
namespace aura { namespace aura {
...@@ -53,6 +54,13 @@ ASH_PUBLIC_EXPORT extern const aura::WindowProperty<int32_t>* const ...@@ -53,6 +54,13 @@ ASH_PUBLIC_EXPORT extern const aura::WindowProperty<int32_t>* const
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<bool>* const ASH_PUBLIC_EXPORT extern const aura::WindowProperty<bool>* const
kShowInOverviewKey; kShowInOverviewKey;
// A property key to store the active color on the window frame.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<SkColor>* const
kFrameActiveColorKey;
// A property key to store the inactive color on the window frame.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<SkColor>* const
kFrameInactiveColorKey;
// A property key to store ash::WindowPinType for a window. // A property key to store ash::WindowPinType for a window.
// When setting this property to PINNED or TRUSTED_PINNED, the window manager // When setting this property to PINNED or TRUSTED_PINNED, the window manager
// will try to fullscreen the window and pin it on the top of the screen. If the // will try to fullscreen the window and pin it on the top of the screen. If the
......
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