Skip to content

Commit

Permalink
Moves CustomFrameViewAsh to common
Browse files Browse the repository at this point in the history
As part of this I'm introducing a pure virtual interface for
ImmersiveFullscreenController. I'm not entirely positive I'll need
this interface long term, but I'll definitely need it in the short
term.

BUG=634972,548435
TEST=none
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2222653002
Cr-Commit-Position: refs/heads/master@{#410363}
  • Loading branch information
sky authored and Commit bot committed Aug 8, 2016
1 parent 2405bb1 commit 2fabae9
Show file tree
Hide file tree
Showing 32 changed files with 259 additions and 232 deletions.
10 changes: 5 additions & 5 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
'common/frame/caption_buttons/frame_size_button.cc',
'common/frame/caption_buttons/frame_size_button.h',
'common/frame/caption_buttons/frame_size_button_delegate.h',
'common/frame/custom_frame_view_ash.cc',
'common/frame/custom_frame_view_ash.h',
'common/frame/default_header_painter.cc',
'common/frame/default_header_painter.h',
'common/frame/frame_border_hit_test.cc',
Expand Down Expand Up @@ -411,6 +413,8 @@
'common/wm/forwarding_layer_delegate.h',
'common/wm/fullscreen_window_finder.cc',
'common/wm/fullscreen_window_finder.h',
'common/wm/immersive/wm_immersive_fullscreen_controller.h',
'common/wm/immersive/wm_immersive_fullscreen_controller_delegate.h',
'common/wm/immersive_revealed_lock.cc',
'common/wm/immersive_revealed_lock.h',
'common/wm/lock_state_observer.h',
Expand Down Expand Up @@ -586,10 +590,6 @@
'first_run/first_run_helper.h',
'first_run/first_run_helper_impl.cc',
'first_run/first_run_helper_impl.h',
'frame/custom_frame_view_ash.cc',
'frame/custom_frame_view_ash.h',
'frame/frame_border_hit_test_controller.cc',
'frame/frame_border_hit_test_controller.h',
'high_contrast/high_contrast_controller.cc',
'high_contrast/high_contrast_controller.h',
'host/ash_window_tree_host.cc',
Expand Down Expand Up @@ -925,6 +925,7 @@
'common/accelerators/accelerator_table_unittest.cc',
'common/display/display_info_unittest.cc',
'common/frame/caption_buttons/frame_caption_button_container_view_unittest.cc',
'common/frame/custom_frame_view_ash_unittest.cc',
'common/frame/default_header_painter_unittest.cc',
'common/material_design/material_design_controller_unittest.cc',
'common/popup_message_unittest.cc',
Expand Down Expand Up @@ -980,7 +981,6 @@
'extended_desktop_unittest.cc',
'focus_cycler_unittest.cc',
'frame/caption_buttons/frame_size_button_unittest.cc',
'frame/custom_frame_view_ash_unittest.cc',
'host/ash_window_tree_host_x11_unittest.cc',
'magnifier/magnification_controller_unittest.cc',
'metrics/desktop_task_switch_metric_recorder_unittest.cc',
Expand Down
6 changes: 6 additions & 0 deletions ash/aura/wm_shell_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ash/shell.h"
#include "ash/touch/touch_uma.h"
#include "ash/wm/drag_window_resizer.h"
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/wm/maximize_mode/maximize_mode_event_handler_aura.h"
#include "ash/wm/screen_pinning_controller.h"
#include "ash/wm/window_cycle_event_filter_aura.h"
Expand Down Expand Up @@ -185,6 +186,11 @@ WmShellAura::CreateScopedDisableInternalMouseAndKeyboard() {
return nullptr;
}

std::unique_ptr<WmImmersiveFullscreenController>
WmShellAura::CreateImmersiveFullscreenController() {
return base::MakeUnique<ImmersiveFullscreenController>();
}

void WmShellAura::OnOverviewModeStarting() {
FOR_EACH_OBSERVER(ShellObserver, *shell_observers(),
OnOverviewModeStarting());
Expand Down
2 changes: 2 additions & 0 deletions ash/aura/wm_shell_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ASH_EXPORT WmShellAura : public WmShell,
override;
std::unique_ptr<ScopedDisableInternalMouseAndKeyboard>
CreateScopedDisableInternalMouseAndKeyboard() override;
std::unique_ptr<WmImmersiveFullscreenController>
CreateImmersiveFullscreenController() override;
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
SessionStateDelegate* GetSessionStateDelegate() override;
Expand Down
11 changes: 11 additions & 0 deletions ash/aura/wm_window_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ash/screen_util.h"
#include "ash/shelf/shelf_util.h"
#include "ash/shell.h"
#include "ash/wm/resize_handle_window_targeter.h"
#include "ash/wm/resize_shadow_controller.h"
#include "ash/wm/window_animations.h"
#include "ash/wm/window_mirror_view.h"
Expand Down Expand Up @@ -294,6 +295,10 @@ void WmWindowAura::SetIntProperty(WmWindowProperty key, int value) {
SetShelfIDForWindow(value, window_);
return;
}
if (key == WmWindowProperty::TOP_VIEW_INSET) {
window_->SetProperty(aura::client::kTopViewInset, value);
return;
}

NOTREACHED();
}
Expand Down Expand Up @@ -649,6 +654,12 @@ void WmWindowAura::HideResizeShadow() {
resize_shadow_controller->HideShadow(window_);
}

void WmWindowAura::InstallResizeHandleWindowTargeter(
WmImmersiveFullscreenController* immersive_fullscreen_controller) {
window_->SetEventTargeter(base::MakeUnique<ResizeHandleWindowTargeter>(
window_, immersive_fullscreen_controller));
}

void WmWindowAura::SetBoundsInScreenBehaviorForChildren(
BoundsInScreenBehavior behavior) {
window_->SetProperty(
Expand Down
3 changes: 3 additions & 0 deletions ash/aura/wm_window_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class ASH_EXPORT WmWindowAura : public WmWindow,
std::vector<WmWindow*> GetChildren() override;
void ShowResizeShadow(int component) override;
void HideResizeShadow() override;
void InstallResizeHandleWindowTargeter(
WmImmersiveFullscreenController* immersive_fullscreen_controller)
override;
void SetBoundsInScreenBehaviorForChildren(
BoundsInScreenBehavior behavior) override;
void SetSnapsChildrenToPhysicalPixelBoundary() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/frame/custom_frame_view_ash.h"
#include "ash/common/frame/custom_frame_view_ash.h"

#include <algorithm>
#include <vector>

#include "ash/aura/wm_window_aura.h"
#include "ash/common/ash_switches.h"
#include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/common/frame/default_header_painter.h"
Expand All @@ -16,18 +15,16 @@
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shell_observer.h"
#include "ash/common/wm/immersive/wm_immersive_fullscreen_controller.h"
#include "ash/common/wm/immersive/wm_immersive_fullscreen_controller_delegate.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm/window_state_delegate.h"
#include "ash/common/wm/window_state_observer.h"
#include "ash/common/wm_lookup.h"
#include "ash/common/wm_shell.h"
#include "ash/frame/frame_border_hit_test_controller.h"
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/wm/window_state_aura.h"
#include "base/command_line.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ash/common/wm_window.h"
#include "ash/common/wm_window_observer.h"
#include "ash/common/wm_window_property.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
Expand All @@ -39,6 +36,8 @@
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"

namespace ash {

namespace {

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -47,19 +46,19 @@ namespace {
// Handles a user's fullscreen request (Shift+F4/F4). Puts the window into
// immersive fullscreen if immersive fullscreen is enabled for non-browser
// windows.
class CustomFrameViewAshWindowStateDelegate
: public ash::wm::WindowStateDelegate,
public ash::wm::WindowStateObserver,
public aura::WindowObserver {
class CustomFrameViewAshWindowStateDelegate : public wm::WindowStateDelegate,
public wm::WindowStateObserver,
public WmWindowObserver {
public:
CustomFrameViewAshWindowStateDelegate(
ash::wm::WindowState* window_state,
ash::CustomFrameViewAsh* custom_frame_view)
: window_state_(NULL) {
immersive_fullscreen_controller_.reset(
new ash::ImmersiveFullscreenController);
custom_frame_view->InitImmersiveFullscreenControllerForView(
immersive_fullscreen_controller_.get());
CustomFrameViewAshWindowStateDelegate(wm::WindowState* window_state,
CustomFrameViewAsh* custom_frame_view)
: window_state_(nullptr) {
immersive_fullscreen_controller_ =
WmShell::Get()->CreateImmersiveFullscreenController();
if (immersive_fullscreen_controller_) {
custom_frame_view->InitImmersiveFullscreenControllerForView(
immersive_fullscreen_controller_.get());
}

// Add a window state observer to exit fullscreen properly in case
// fullscreen is exited without going through
Expand All @@ -68,72 +67,63 @@ class CustomFrameViewAshWindowStateDelegate
// TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048
window_state_ = window_state;
window_state_->AddObserver(this);
GetAuraWindow()->AddObserver(this);
window_state_->window()->AddObserver(this);
}
~CustomFrameViewAshWindowStateDelegate() override {
if (window_state_) {
window_state_->RemoveObserver(this);
GetAuraWindow()->RemoveObserver(this);
window_state_->window()->RemoveObserver(this);
}
}

private:
aura::Window* GetAuraWindow() {
return ash::WmWindowAura::GetAuraWindow(window_state_->window());
}

// Overridden from ash::wm::WindowStateDelegate:
bool ToggleFullscreen(ash::wm::WindowState* window_state) override {
// Overridden from wm::WindowStateDelegate:
bool ToggleFullscreen(wm::WindowState* window_state) override {
bool enter_fullscreen = !window_state->IsFullscreen();
if (enter_fullscreen) {
GetAuraWindow()->SetProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
} else {
if (enter_fullscreen)
window_state_->window()->SetShowState(ui::SHOW_STATE_FULLSCREEN);
else
window_state->Restore();
}
if (immersive_fullscreen_controller_) {
immersive_fullscreen_controller_->SetEnabled(
ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER,
enter_fullscreen);
WmImmersiveFullscreenController::WINDOW_TYPE_OTHER, enter_fullscreen);
}
return true;
}
// Overridden from aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override {
// Overridden from WmWindowObserver:
void OnWindowDestroying(WmWindow* window) override {
window_state_->RemoveObserver(this);
GetAuraWindow()->RemoveObserver(this);
window_state_ = NULL;
window->RemoveObserver(this);
window_state_ = nullptr;
}
// Overridden from ash::wm::WindowStateObserver:
void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state,
ash::wm::WindowStateType old_type) override {
// Overridden from wm::WindowStateObserver:
void OnPostWindowStateTypeChange(wm::WindowState* window_state,
wm::WindowStateType old_type) override {
if (!window_state->IsFullscreen() && !window_state->IsMinimized() &&
immersive_fullscreen_controller_.get() &&
immersive_fullscreen_controller_ &&
immersive_fullscreen_controller_->IsEnabled()) {
immersive_fullscreen_controller_->SetEnabled(
ash::ImmersiveFullscreenController::WINDOW_TYPE_OTHER, false);
WmImmersiveFullscreenController::WINDOW_TYPE_OTHER, false);
}
}

ash::wm::WindowState* window_state_;
std::unique_ptr<ash::ImmersiveFullscreenController>
wm::WindowState* window_state_;
std::unique_ptr<WmImmersiveFullscreenController>
immersive_fullscreen_controller_;

DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate);
};

} // namespace

namespace ash {

///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView

// View which paints the header. It slides off and on screen in immersive
// fullscreen.
class CustomFrameViewAsh::HeaderView
: public views::View,
public ImmersiveFullscreenController::Delegate,
public WmImmersiveFullscreenControllerDelegate,
public ShellObserver {
public:
// |frame| is the widget that the caption buttons act on.
Expand Down Expand Up @@ -179,7 +169,7 @@ class CustomFrameViewAsh::HeaderView
views::View* avatar_icon() const { return avatar_icon_; }

private:
// ImmersiveFullscreenController::Delegate:
// WmImmersiveFullscreenControllerDelegate:
void OnImmersiveRevealStarted() override;
void OnImmersiveRevealEnded() override;
void OnImmersiveFullscreenExited() override;
Expand All @@ -206,7 +196,7 @@ class CustomFrameViewAsh::HeaderView

CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
: frame_(frame),
header_painter_(new ash::DefaultHeaderPainter),
header_painter_(new DefaultHeaderPainter),
avatar_icon_(NULL),
caption_button_container_(NULL),
fullscreen_visible_fraction_(0) {
Expand Down Expand Up @@ -315,12 +305,12 @@ void CustomFrameViewAsh::HeaderView::ChildPreferredSizeChanged(
// CustomFrameViewAsh::HeaderView, ShellObserver overrides:

void CustomFrameViewAsh::HeaderView::OnOverviewModeStarting() {
if (ash::MaterialDesignController::IsOverviewMaterial())
if (MaterialDesignController::IsOverviewMaterial())
caption_button_container_->SetVisible(false);
}

void CustomFrameViewAsh::HeaderView::OnOverviewModeEnded() {
if (ash::MaterialDesignController::IsOverviewMaterial())
if (MaterialDesignController::IsOverviewMaterial())
caption_button_container_->SetVisible(true);
}

Expand All @@ -336,7 +326,7 @@ void CustomFrameViewAsh::HeaderView::OnMaximizeModeEnded() {

///////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh::HeaderView,
// ImmersiveFullscreenController::Delegate overrides:
// WmImmersiveFullscreenControllerDelegate overrides:

void CustomFrameViewAsh::HeaderView::OnImmersiveRevealStarted() {
fullscreen_visible_fraction_ = 0;
Expand Down Expand Up @@ -448,17 +438,16 @@ bool CustomFrameViewAsh::OverlayView::DoesIntersectRect(
const char CustomFrameViewAsh::kViewClassName[] = "CustomFrameViewAsh";

CustomFrameViewAsh::CustomFrameViewAsh(views::Widget* frame)
: frame_(frame),
header_view_(new HeaderView(frame)),
frame_border_hit_test_controller_(
new FrameBorderHitTestController(frame_)) {
: frame_(frame), header_view_(new HeaderView(frame)) {
WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame);
frame_window->InstallResizeHandleWindowTargeter(nullptr);
// |header_view_| is set as the non client view's overlay view so that it can
// overlay the web contents in immersive fullscreen.
frame->non_client_view()->SetOverlayView(new OverlayView(header_view_));

// A delegate for a more complex way of fullscreening the window may already
// be set. This is the case for packaged apps.
wm::WindowState* window_state = wm::GetWindowState(frame->GetNativeWindow());
wm::WindowState* window_state = frame_window->GetWindowState();
if (!window_state->HasDelegate()) {
window_state->SetDelegate(std::unique_ptr<wm::WindowStateDelegate>(
new CustomFrameViewAshWindowStateDelegate(window_state, this)));
Expand All @@ -468,7 +457,7 @@ CustomFrameViewAsh::CustomFrameViewAsh(views::Widget* frame)
CustomFrameViewAsh::~CustomFrameViewAsh() {}

void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
ImmersiveFullscreenController* immersive_fullscreen_controller) {
WmImmersiveFullscreenController* immersive_fullscreen_controller) {
immersive_fullscreen_controller->Init(header_view_, frame_, header_view_);
}

Expand Down Expand Up @@ -530,8 +519,9 @@ gfx::Size CustomFrameViewAsh::GetPreferredSize() const {

void CustomFrameViewAsh::Layout() {
views::NonClientFrameView::Layout();
frame_->GetNativeWindow()->SetProperty(aura::client::kTopViewInset,
NonClientTopBorderHeight());
WmWindow* frame_window = WmLookup::Get()->GetWindowForWidget(frame_);
frame_window->SetIntProperty(WmWindowProperty::TOP_VIEW_INSET,
NonClientTopBorderHeight());
}

const char* CustomFrameViewAsh::GetClassName() const {
Expand Down
Loading

0 comments on commit 2fabae9

Please sign in to comment.