Commit 21b079d1 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Use the CustomFrameViewAsh for client controlled shell surface.

This will not change the functionality now, but will be used
when caption is moved to chrome for ARC++ apps.

BUG=762816

Change-Id: Ia25d13eba37b31677a265b9f3e8b09953a5dd8e5
Reviewed-on: https://chromium-review.googlesource.com/786545
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520811}
parent 0fa28d6d
...@@ -162,25 +162,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate, ...@@ -162,25 +162,6 @@ class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
} // namespace } // namespace
////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAshBase, public:
CustomFrameViewAshBase::CustomFrameViewAshBase() {
Shell::Get()->AddShellObserver(this);
}
CustomFrameViewAshBase::~CustomFrameViewAshBase() {
Shell::Get()->RemoveShellObserver(this);
}
void CustomFrameViewAshBase::OnOverviewModeStarting() {
SetShouldPaintHeader(false);
}
void CustomFrameViewAshBase::OnOverviewModeEnded() {
SetShouldPaintHeader(true);
}
// static // static
bool CustomFrameViewAsh::use_empty_minimum_size_for_test_ = false; bool CustomFrameViewAsh::use_empty_minimum_size_for_test_ = false;
...@@ -285,7 +266,7 @@ void CustomFrameViewAsh::OverlayView::Layout() { ...@@ -285,7 +266,7 @@ void CustomFrameViewAsh::OverlayView::Layout() {
int onscreen_height = header_height_ int onscreen_height = header_height_
? *header_height_ ? *header_height_
: header_view_->GetPreferredOnScreenHeight(); : header_view_->GetPreferredOnScreenHeight();
if (onscreen_height == 0) { if (onscreen_height == 0 || !enabled()) {
header_view_->SetVisible(false); header_view_->SetVisible(false);
} else { } else {
const int height = const int height =
...@@ -340,9 +321,12 @@ CustomFrameViewAsh::CustomFrameViewAsh( ...@@ -340,9 +321,12 @@ CustomFrameViewAsh::CustomFrameViewAsh(
new CustomFrameViewAshWindowStateDelegate(window_state, this, new CustomFrameViewAshWindowStateDelegate(window_state, this,
enable_immersive))); enable_immersive)));
} }
Shell::Get()->AddShellObserver(this);
} }
CustomFrameViewAsh::~CustomFrameViewAsh() = default; CustomFrameViewAsh::~CustomFrameViewAsh() {
Shell::Get()->RemoveShellObserver(this);
}
void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
ImmersiveFullscreenController* immersive_fullscreen_controller) { ImmersiveFullscreenController* immersive_fullscreen_controller) {
...@@ -428,6 +412,8 @@ gfx::Size CustomFrameViewAsh::CalculatePreferredSize() const { ...@@ -428,6 +412,8 @@ gfx::Size CustomFrameViewAsh::CalculatePreferredSize() const {
} }
void CustomFrameViewAsh::Layout() { void CustomFrameViewAsh::Layout() {
if (!enabled())
return;
views::NonClientFrameView::Layout(); views::NonClientFrameView::Layout();
aura::Window* frame_window = frame_->GetNativeWindow(); aura::Window* frame_window = frame_->GetNativeWindow();
frame_window->SetProperty(aura::client::kTopViewInset, frame_window->SetProperty(aura::client::kTopViewInset,
...@@ -439,7 +425,7 @@ const char* CustomFrameViewAsh::GetClassName() const { ...@@ -439,7 +425,7 @@ const char* CustomFrameViewAsh::GetClassName() const {
} }
gfx::Size CustomFrameViewAsh::GetMinimumSize() const { gfx::Size CustomFrameViewAsh::GetMinimumSize() const {
if (use_empty_minimum_size_for_test_) if (use_empty_minimum_size_for_test_ || !enabled())
return gfx::Size(); return gfx::Size();
gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize()); gfx::Size min_client_view_size(frame_->client_view()->GetMinimumSize());
...@@ -495,6 +481,14 @@ void CustomFrameViewAsh::SetShouldPaintHeader(bool paint) { ...@@ -495,6 +481,14 @@ void CustomFrameViewAsh::SetShouldPaintHeader(bool paint) {
header_view_->SetShouldPaintHeader(paint); header_view_->SetShouldPaintHeader(paint);
} }
void CustomFrameViewAsh::OnOverviewModeStarting() {
SetShouldPaintHeader(false);
}
void CustomFrameViewAsh::OnOverviewModeEnded() {
SetShouldPaintHeader(true);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, private: // CustomFrameViewAsh, private:
...@@ -513,9 +507,9 @@ CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() { ...@@ -513,9 +507,9 @@ CustomFrameViewAsh::GetFrameCaptionButtonContainerViewForTest() {
} }
int CustomFrameViewAsh::NonClientTopBorderHeight() const { int CustomFrameViewAsh::NonClientTopBorderHeight() const {
// The frame should not occupy the window area when it's not visible // The frame should not occupy the window area when it's in fullscreen,
// or in fullscreen. // not visible or disabled.
if (frame_->IsFullscreen() || !visible()) if (frame_->IsFullscreen() || !visible() || !enabled())
return 0; return 0;
const bool should_hide_titlebar_in_tablet_mode = const bool should_hide_titlebar_in_tablet_mode =
......
...@@ -32,30 +32,14 @@ enum class FrameBackButtonState { ...@@ -32,30 +32,14 @@ enum class FrameBackButtonState {
kVisibleDisabled, kVisibleDisabled,
}; };
// A base class for v2 and ARC apps to hide header in overview mode.
class ASH_EXPORT CustomFrameViewAshBase : public views::NonClientFrameView,
public ash::ShellObserver {
public:
CustomFrameViewAshBase();
~CustomFrameViewAshBase() override;
// ash::ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
// If |paint| is false, we should not paint the header. Used for overview mode
// with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the
// header of v2 and ARC apps.
virtual void SetShouldPaintHeader(bool paint) {}
};
// A NonClientFrameView used for packaged apps, dialogs and other non-browser // A NonClientFrameView used for packaged apps, dialogs and other non-browser
// windows. It supports immersive fullscreen. When in immersive fullscreen, the // windows. It supports immersive fullscreen. When in immersive fullscreen, the
// client view takes up the entire widget and the window header is an overlay. // client view takes up the entire widget and the window header is an overlay.
// The window header overlay slides onscreen when the user hovers the mouse at // The window header overlay slides onscreen when the user hovers the mouse at
// the top of the screen. See also views::CustomFrameView and // the top of the screen. See also views::CustomFrameView and
// BrowserNonClientFrameViewAsh. // BrowserNonClientFrameViewAsh.
class ASH_EXPORT CustomFrameViewAsh : public CustomFrameViewAshBase { class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView,
public ash::ShellObserver {
public: public:
// Internal class name. // Internal class name.
static const char kViewClassName[]; static const char kViewClassName[];
...@@ -116,8 +100,14 @@ class ASH_EXPORT CustomFrameViewAsh : public CustomFrameViewAshBase { ...@@ -116,8 +100,14 @@ class ASH_EXPORT CustomFrameViewAsh : public CustomFrameViewAshBase {
void SchedulePaintInRect(const gfx::Rect& r) override; void SchedulePaintInRect(const gfx::Rect& r) override;
void SetVisible(bool visible) override; void SetVisible(bool visible) override;
// ash::CustomFrameViewAshBase: // If |paint| is false, we should not paint the header. Used for overview mode
void SetShouldPaintHeader(bool paint) override; // with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the
// header of v2 and ARC apps.
virtual void SetShouldPaintHeader(bool paint);
// ash::ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
const views::View* GetAvatarIconViewForTest() const; const views::View* GetAvatarIconViewForTest() const;
......
...@@ -45,7 +45,7 @@ void ClientControlledState::HandleTransitionEvents(WindowState* window_state, ...@@ -45,7 +45,7 @@ void ClientControlledState::HandleTransitionEvents(WindowState* window_state,
return; return;
} }
mojom::WindowStateType next_state_type = GetStateForTransitionEvent(event); mojom::WindowStateType next_state_type = GetStateForTransitionEvent(event);
delegate_->HandleWindowStateRequest(state_type_, next_state_type); delegate_->HandleWindowStateRequest(window_state, next_state_type);
mojom::WindowStateType old_state_type = state_type_; mojom::WindowStateType old_state_type = state_type_;
bool was_pinned = window_state->IsPinned(); bool was_pinned = window_state->IsPinned();
...@@ -74,7 +74,7 @@ void ClientControlledState::HandleTransitionEvents(WindowState* window_state, ...@@ -74,7 +74,7 @@ void ClientControlledState::HandleTransitionEvents(WindowState* window_state,
VLOG(1) << "Processing State Transtion: event=" << event->type() VLOG(1) << "Processing State Transtion: event=" << event->type()
<< ", state=" << state_type_ << ", next_state=" << next_state; << ", state=" << state_type_ << ", next_state=" << next_state;
// Then ask delegate to handle the window state change. // Then ask delegate to handle the window state change.
delegate_->HandleWindowStateRequest(state_type_, next_state); delegate_->HandleWindowStateRequest(window_state, next_state);
break; break;
} }
case WM_EVENT_SHOW_INACTIVE: case WM_EVENT_SHOW_INACTIVE:
...@@ -152,7 +152,7 @@ void ClientControlledState::HandleBoundsEvents(WindowState* window_state, ...@@ -152,7 +152,7 @@ void ClientControlledState::HandleBoundsEvents(WindowState* window_state,
// In pinned state, it should ignore the SetBounds from window manager // In pinned state, it should ignore the SetBounds from window manager
// or user. // or user.
} else { } else {
delegate_->HandleBoundsRequest(window_state->GetStateType(), delegate_->HandleBoundsRequest(window_state,
set_bounds_event->requested_bounds()); set_bounds_event->requested_bounds());
} }
break; break;
......
...@@ -30,16 +30,16 @@ class ASH_EXPORT ClientControlledState : public BaseState { ...@@ -30,16 +30,16 @@ class ASH_EXPORT ClientControlledState : public BaseState {
class Delegate { class Delegate {
public: public:
virtual ~Delegate() = default; virtual ~Delegate() = default;
// Handles the state change from |current_state| to |requested_state|. // Handles the state change of |window_state| to |requested_state|.
// Delegate may decide to ignore the state change, proceed with the state // Delegate may decide to ignore the state change, proceed with the state
// change, or can move to a different state. // change, or can move to a different state.
virtual void HandleWindowStateRequest( virtual void HandleWindowStateRequest(
mojom::WindowStateType current_state, WindowState* window_state,
mojom::WindowStateType requested_state) = 0; mojom::WindowStateType requested_state) = 0;
// Handles the bounds change request. |current_state| specifies the current // Handles the bounds change request for |window_state|. Delegate
// window state. Delegate may choose to ignore the request, set the given // may choose to ignore the request, set the given bounds, or set
// bounds, or set the different bounds. // the different bounds.
virtual void HandleBoundsRequest(mojom::WindowStateType current_state, virtual void HandleBoundsRequest(WindowState* window_state,
const gfx::Rect& requested_bounds) = 0; const gfx::Rect& requested_bounds) = 0;
}; };
......
...@@ -25,13 +25,13 @@ class TestClientControlledStateDelegate ...@@ -25,13 +25,13 @@ class TestClientControlledStateDelegate
TestClientControlledStateDelegate() = default; TestClientControlledStateDelegate() = default;
~TestClientControlledStateDelegate() override = default; ~TestClientControlledStateDelegate() override = default;
void HandleWindowStateRequest(mojom::WindowStateType current_state, void HandleWindowStateRequest(WindowState* window_state,
mojom::WindowStateType next_state) override { mojom::WindowStateType next_state) override {
old_state_ = current_state; old_state_ = window_state->GetStateType();
new_state_ = next_state; new_state_ = next_state;
} }
void HandleBoundsRequest(mojom::WindowStateType current_state, void HandleBoundsRequest(WindowState* window_state,
const gfx::Rect& bounds) override { const gfx::Rect& bounds) override {
requested_bounds_ = bounds; requested_bounds_ = bounds;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/wm/drag_window_resizer.h" #include "ash/wm/drag_window_resizer.h"
#include "ash/wm/window_resizer.h" #include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -67,16 +68,26 @@ const struct { ...@@ -67,16 +68,26 @@ const struct {
{ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN},
{ui::VKEY_F4, ui::EF_ALT_DOWN}}; {ui::VKEY_F4, ui::EF_ALT_DOWN}};
class CustomFrameView : public ash::CustomFrameViewAshBase { class CustomFrameView : public ash::CustomFrameViewAsh {
public: public:
using ShapeRects = std::vector<gfx::Rect>; using ShapeRects = std::vector<gfx::Rect>;
explicit CustomFrameView(views::Widget* widget) : widget_(widget) {} CustomFrameView(views::Widget* widget, bool enabled)
: CustomFrameViewAsh(widget) {
SetEnabled(enabled);
if (!enabled)
CustomFrameViewAsh::SetShouldPaintHeader(false);
}
~CustomFrameView() override {} ~CustomFrameView() override {}
// Overridden from ash::CustomFrameViewAshBase: // Overridden from ash::CustomFrameViewAshBase:
void SetShouldPaintHeader(bool paint) override { void SetShouldPaintHeader(bool paint) override {
aura::Window* window = widget_->GetNativeWindow(); if (enabled()) {
CustomFrameViewAsh::SetShouldPaintHeader(paint);
return;
}
aura::Window* window = GetWidget()->GetNativeWindow();
ui::Layer* layer = window->layer(); ui::Layer* layer = window->layer();
if (paint) { if (paint) {
if (layer->alpha_shape()) { if (layer->alpha_shape()) {
...@@ -99,23 +110,46 @@ class CustomFrameView : public ash::CustomFrameViewAshBase { ...@@ -99,23 +110,46 @@ class CustomFrameView : public ash::CustomFrameViewAshBase {
} }
// Overridden from views::NonClientFrameView: // Overridden from views::NonClientFrameView:
gfx::Rect GetBoundsForClientView() const override { return bounds(); } gfx::Rect GetBoundsForClientView() const override {
if (enabled())
return ash::CustomFrameViewAsh::GetBoundsForClientView();
return bounds();
}
gfx::Rect GetWindowBoundsForClientBounds( gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const override { const gfx::Rect& client_bounds) const override {
if (enabled()) {
return ash::CustomFrameViewAsh::GetWindowBoundsForClientBounds(
client_bounds);
}
return client_bounds; return client_bounds;
} }
int NonClientHitTest(const gfx::Point& point) override { int NonClientHitTest(const gfx::Point& point) override {
return widget_->client_view()->NonClientHitTest(point); if (enabled())
return ash::CustomFrameViewAsh::NonClientHitTest(point);
return GetWidget()->client_view()->NonClientHitTest(point);
}
void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {
if (enabled())
return ash::CustomFrameViewAsh::GetWindowMask(size, window_mask);
}
void ResetWindowControls() override {
if (enabled())
return ash::CustomFrameViewAsh::ResetWindowControls();
}
void UpdateWindowIcon() override {
if (enabled())
return ash::CustomFrameViewAsh::ResetWindowControls();
}
void UpdateWindowTitle() override {
if (enabled())
return ash::CustomFrameViewAsh::UpdateWindowTitle();
}
void SizeConstraintsChanged() override {
if (enabled())
return ash::CustomFrameViewAsh::SizeConstraintsChanged();
} }
void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {}
void ResetWindowControls() override {}
void UpdateWindowIcon() override {}
void UpdateWindowTitle() override {}
void SizeConstraintsChanged() override {}
private: private:
views::Widget* const widget_;
DISALLOW_COPY_AND_ASSIGN(CustomFrameView); DISALLOW_COPY_AND_ASSIGN(CustomFrameView);
}; };
...@@ -172,6 +206,26 @@ class ShellSurfaceWidget : public views::Widget { ...@@ -172,6 +206,26 @@ class ShellSurfaceWidget : public views::Widget {
DISALLOW_COPY_AND_ASSIGN(ShellSurfaceWidget); DISALLOW_COPY_AND_ASSIGN(ShellSurfaceWidget);
}; };
// A place holder to disable default implementation created by
// ash::CustomFrameViewAsh, which triggers immersive fullscreen etc, which
// we don't need.
class CustomWindowStateDelegate : public ash::wm::WindowStateDelegate {
public:
CustomWindowStateDelegate() {}
~CustomWindowStateDelegate() override {}
// Overridden from ash::wm::WindowStateDelegate:
bool ToggleFullscreen(ash::wm::WindowState* window_state) override {
return false;
}
bool RestoreAlwaysOnTop(ash::wm::WindowState* window_state) override {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(CustomWindowStateDelegate);
};
} // namespace } // namespace
// Surface state associated with each configure request. // Surface state associated with each configure request.
...@@ -799,10 +853,11 @@ views::NonClientFrameView* ShellSurface::CreateNonClientFrameView( ...@@ -799,10 +853,11 @@ views::NonClientFrameView* ShellSurface::CreateNonClientFrameView(
aura::Window* window = widget_->GetNativeWindow(); aura::Window* window = widget_->GetNativeWindow();
// ShellSurfaces always use immersive mode. // ShellSurfaces always use immersive mode.
window->SetProperty(aura::client::kImmersiveFullscreenKey, true); window->SetProperty(aura::client::kImmersiveFullscreenKey, true);
if (frame_enabled_) if (!frame_enabled_) {
return new ash::CustomFrameViewAsh(widget); ash::wm::WindowState* window_state = ash::wm::GetWindowState(window);
window_state->SetDelegate(std::make_unique<CustomWindowStateDelegate>());
return new CustomFrameView(widget); }
return new CustomFrameView(widget, frame_enabled_);
} }
bool ShellSurface::WidgetHasHitTestMask() const { bool ShellSurface::WidgetHasHitTestMask() const {
......
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