Skip to content

Commit

Permalink
Move MaximizeModeController into ash/common
Browse files Browse the repository at this point in the history
BUG=612629
TEST=covered by tests
R=jamescook@chromium.org, yusukes@chromium.org
TBR=yusukes@chromium.org

Review-Url: https://codereview.chromium.org/2118643002
Cr-Commit-Position: refs/heads/master@{#403485}
  • Loading branch information
sky authored and Commit bot committed Jul 1, 2016
1 parent 5709ded commit e2bde21
Show file tree
Hide file tree
Showing 45 changed files with 140 additions and 98 deletions.
2 changes: 1 addition & 1 deletion ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/volume_control_delegate.h"
#include "ash/common/system/web_notification/web_notification_tray.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm/mru_window_tracker.h"
#include "ash/common/wm/overview/window_selector_controller.h"
#include "ash/common/wm/window_state.h"
Expand Down Expand Up @@ -53,7 +54,6 @@
#include "ash/system/tray/system_tray.h"
#include "ash/touch/touch_hud_debug.h"
#include "ash/utility/screenshot_controller.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/power_button_controller.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_state_aura.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/accelerators/debug_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/accelerators/accelerator_commands.h"
#include "ash/common/ash_switches.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/debug.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/desktop_background/user_wallpaper_delegate.h"
Expand All @@ -16,7 +17,6 @@
#include "ash/shell_delegate.h"
#include "ash/system/toast/toast_data.h"
#include "ash/system/toast/toast_manager.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/metrics/user_metrics.h"
Expand Down
2 changes: 1 addition & 1 deletion ash/app_list/app_list_presenter_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/common/ash_switches.h"
#include "ash/common/shelf/shelf_types.h"
#include "ash/common/shell_window_ids.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/root_window_controller.h"
Expand All @@ -16,7 +17,6 @@
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "base/command_line.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_switches.h"
Expand Down
6 changes: 3 additions & 3 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,15 @@
'common/wm/focus_rules.h',
'common/wm/fullscreen_window_finder.cc',
'common/wm/fullscreen_window_finder.h',
'common/wm/maximize_mode/maximize_mode_controller.cc',
'common/wm/maximize_mode/maximize_mode_controller.h',
'common/wm/maximize_mode/maximize_mode_event_handler.cc',
'common/wm/maximize_mode/maximize_mode_event_handler.h',
'common/wm/maximize_mode/maximize_mode_window_manager.cc',
'common/wm/maximize_mode/maximize_mode_window_manager.h',
'common/wm/maximize_mode/maximize_mode_window_state.cc',
'common/wm/maximize_mode/maximize_mode_window_state.h',
'common/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h',
'common/wm/maximize_mode/workspace_backdrop_delegate.cc',
'common/wm/maximize_mode/workspace_backdrop_delegate.h',
'common/wm/mru_window_tracker.cc',
Expand Down Expand Up @@ -686,11 +689,8 @@
'wm/lock_state_observer.h',
'wm/lock_window_state.cc',
'wm/lock_window_state.h',
'wm/maximize_mode/maximize_mode_controller.cc',
'wm/maximize_mode/maximize_mode_controller.h',
'wm/maximize_mode/maximize_mode_event_handler_aura.cc',
'wm/maximize_mode/maximize_mode_event_handler_aura.h',
'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h',
'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.cc',
'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h',
'wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.cc',
Expand Down
23 changes: 23 additions & 0 deletions ash/aura/wm_shell_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/aura/wm_window_aura.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shell_observer.h"
#include "ash/common/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h"
#include "ash/common/wm/mru_window_tracker.h"
#include "ash/common/wm/overview/window_selector_controller.h"
#include "ash/common/wm_activation_observer.h"
Expand All @@ -27,6 +28,14 @@
#include "ash/virtual_keyboard_controller.h"
#endif

#if defined(USE_X11)
#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h"
#endif

#if defined(USE_OZONE)
#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h"
#endif

namespace ash {

WmShellAura::WmShellAura() {
Expand Down Expand Up @@ -79,6 +88,10 @@ const DisplayInfo& WmShellAura::GetDisplayInfo(int64_t display_id) const {
return Shell::GetInstance()->display_manager()->GetDisplayInfo(display_id);
}

bool WmShellAura::IsActiveDisplayId(int64_t display_id) const {
return Shell::GetInstance()->display_manager()->IsActiveDisplayId(display_id);
}

bool WmShellAura::IsForceMaximizeOnFirstRun() {
return Shell::GetInstance()->delegate()->IsForceMaximizeOnFirstRun();
}
Expand Down Expand Up @@ -128,6 +141,16 @@ WmShellAura::CreateMaximizeModeEventHandler() {
return base::WrapUnique(new wm::MaximizeModeEventHandlerAura);
}

std::unique_ptr<ScopedDisableInternalMouseAndKeyboard>
WmShellAura::CreateScopedDisableInternalMouseAndKeyboard() {
#if defined(USE_X11)
return base::WrapUnique(new ScopedDisableInternalMouseAndKeyboardX11);
#elif defined(USE_OZONE)
return base::WrapUnique(new ScopedDisableInternalMouseAndKeyboardOzone);
#endif
return nullptr;
}

void WmShellAura::OnOverviewModeStarting() {
FOR_EACH_OBSERVER(ShellObserver, *shell_observers(),
OnOverviewModeStarting());
Expand Down
3 changes: 3 additions & 0 deletions ash/aura/wm_shell_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ASH_EXPORT WmShellAura : public WmShell,
WmWindow* GetRootWindowForDisplayId(int64_t display_id) override;
WmWindow* GetRootWindowForNewWindows() override;
const DisplayInfo& GetDisplayInfo(int64_t display_id) const override;
bool IsActiveDisplayId(int64_t display_id) const override;
bool IsForceMaximizeOnFirstRun() override;
bool IsPinned() override;
void SetPinnedWindow(WmWindow* window) override;
Expand All @@ -48,6 +49,8 @@ class ASH_EXPORT WmShellAura : public WmShell,
wm::WindowState* window_state) override;
std::unique_ptr<wm::MaximizeModeEventHandler> CreateMaximizeModeEventHandler()
override;
std::unique_ptr<ScopedDisableInternalMouseAndKeyboard>
CreateScopedDisableInternalMouseAndKeyboard() override;
void OnOverviewModeStarting() override;
void OnOverviewModeEnded() override;
AccessibilityDelegate* GetAccessibilityDelegate() override;
Expand Down
2 changes: 1 addition & 1 deletion ash/common/ash_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ const char kAshEnableMagnifierKeyScroller[] =

// Enables unified desktop mode.
const char kAshEnableUnifiedDesktop[] = "ash-enable-unified-desktop";
#endif

// Enables the observation of accelerometer events to enter touch-view mode.
const char kAshEnableTouchView[] = "enable-touchview";
#endif

// Enables mirrored screen.
const char kAshEnableMirroredScreen[] = "ash-enable-mirrored-screen";
Expand Down
3 changes: 2 additions & 1 deletion ash/common/ash_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace switches {
// see chromeos::LoginUtil::GetOffTheRecordCommandLine().)

// Please keep alphabetized.
// TODO(sky): fix order!
ASH_EXPORT extern const char kAshAnimateFromBootSplashScreen[];
ASH_EXPORT extern const char kAshCopyHostBackgroundAtBoot[];
ASH_EXPORT extern const char kAshDebugShortcuts[];
Expand All @@ -28,9 +29,9 @@ ASH_EXPORT extern const char kAshDisableTouchExplorationMode[];
#if defined(OS_CHROMEOS)
ASH_EXPORT extern const char kAshEnableFullscreenAppList[];
ASH_EXPORT extern const char kAshEnableMagnifierKeyScroller[];
ASH_EXPORT extern const char kAshEnableTouchView[];
ASH_EXPORT extern const char kAshEnableUnifiedDesktop[];
#endif
ASH_EXPORT extern const char kAshEnableTouchView[];
ASH_EXPORT extern const char kAshEnableMirroredScreen[];
ASH_EXPORT extern const char kAshDisableStableOverviewOrder[];
ASH_EXPORT extern const char kAshEnableStableOverviewOrder[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"

#include <utility>

#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/common/ash_switches.h"
#include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
#include "ash/common/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h"
#include "ash/common/wm_shell.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/time/default_tick_clock.h"
Expand All @@ -24,14 +20,6 @@
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/vector3d_f.h"

#if defined(USE_X11)
#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_x11.h"
#endif

#if defined(USE_OZONE)
#include "ash/wm/maximize_mode/scoped_disable_internal_mouse_and_keyboard_ozone.h"
#endif

#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_thread_manager.h"
#include "ui/chromeos/accelerometer/accelerometer_util.h"
Expand Down Expand Up @@ -97,6 +85,11 @@ bool IsAngleBetweenAccelerometerReadingsStable(
}
#endif // OS_CHROMEOS

bool IsEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshEnableTouchView);
}

} // namespace

MaximizeModeController::MaximizeModeController()
Expand All @@ -110,29 +103,31 @@ MaximizeModeController::MaximizeModeController()
WmShell::Get()->AddShellObserver(this);
WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_INITIALLY_DISABLED);

#if defined(OS_CHROMEOS)
// TODO(jonross): Do not create MaximizeModeController if the flag is
// unavailable. This will require refactoring
// IsMaximizeModeWindowManagerEnabled to check for the existance of the
// controller.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshEnableTouchView)) {
const bool is_enabled = IsEnabled();
if (is_enabled)
WmShell::Get()->AddDisplayObserver(this);

#if defined(OS_CHROMEOS)
if (is_enabled)
chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
}
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
#endif // OS_CHROMEOS
}

MaximizeModeController::~MaximizeModeController() {
WmShell::Get()->RemoveShellObserver(this);
const bool is_enabled = IsEnabled();
if (is_enabled)
WmShell::Get()->RemoveDisplayObserver(this);

#if defined(OS_CHROMEOS)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshEnableTouchView)) {
if (is_enabled)
chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
}
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
this);
#endif // OS_CHROMEOS
Expand Down Expand Up @@ -160,17 +155,17 @@ void MaximizeModeController::EnableMaximizeModeWindowManager(
if (should_enable == is_enabled)
return;

Shell* shell = Shell::GetInstance();
WmShell* shell = WmShell::Get();

if (should_enable) {
maximize_mode_window_manager_.reset(new MaximizeModeWindowManager());
// TODO(jonross): Move the maximize mode notifications from ShellObserver
// to MaximizeModeController::Observer
WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_ENABLED);
shell->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_ENABLED);
shell->OnMaximizeModeStarted();
} else {
maximize_mode_window_manager_.reset();
WmShell::Get()->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_DISABLED);
shell->RecordUserMetricsAction(UMA_MAXIMIZE_MODE_DISABLED);
shell->OnMaximizeModeEnded();
}
}
Expand All @@ -196,7 +191,7 @@ void MaximizeModeController::OnAccelerometerUpdated(
if (!display::Display::HasInternalDisplay())
return;

if (!Shell::GetInstance()->display_manager()->IsActiveDisplayId(
if (!WmShell::Get()->IsActiveDisplayId(
display::Display::InternalDisplayId())) {
return;
}
Expand Down Expand Up @@ -319,12 +314,8 @@ void MaximizeModeController::HandleHingeRotation(
void MaximizeModeController::EnterMaximizeMode() {
// Always reset first to avoid creation before destruction of a previous
// object.
event_blocker_.reset();
#if defined(USE_X11)
event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardX11);
#elif defined(USE_OZONE)
event_blocker_.reset(new ScopedDisableInternalMouseAndKeyboardOzone);
#endif
event_blocker_ =
WmShell::Get()->CreateScopedDisableInternalMouseAndKeyboard();

if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshEnableTouchViewTesting)) {
Expand Down Expand Up @@ -366,7 +357,7 @@ void MaximizeModeController::OnMaximizeModeEnded() {

void MaximizeModeController::OnDisplayConfigurationChanged() {
if (!display::Display::HasInternalDisplay() ||
!Shell::GetInstance()->display_manager()->IsActiveDisplayId(
!WmShell::Get()->IsActiveDisplayId(
display::Display::InternalDisplayId())) {
LeaveMaximizeMode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
#define ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
#ifndef ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
#define ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_

#include <memory>

#include "ash/ash_export.h"
#include "ash/common/shell_observer.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/common/wm_display_observer.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "ui/gfx/geometry/vector3d_f.h"
Expand Down Expand Up @@ -53,7 +53,7 @@ class ASH_EXPORT MaximizeModeController :
public chromeos::PowerManagerClient::Observer,
#endif // OS_CHROMEOS
public ShellObserver,
public WindowTreeHostManager::Observer {
public WmDisplayObserver {
public:
MaximizeModeController();
~MaximizeModeController() override;
Expand Down Expand Up @@ -84,7 +84,7 @@ class ASH_EXPORT MaximizeModeController :
void OnMaximizeModeStarted() override;
void OnMaximizeModeEnded() override;

// WindowTreeHostManager::Observer:
// WmDisplayObserver:
void OnDisplayConfigurationChanged() override;

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -187,4 +187,4 @@ class ASH_EXPORT MaximizeModeController :

} // namespace ash

#endif // ASH_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
#endif // ASH_COMMON_WM_MAXIMIZE_MODE_MAXIMIZE_MODE_CONTROLLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_
#define ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_
#ifndef ASH_COMMON_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_
#define ASH_COMMON_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_

namespace ash {

Expand All @@ -14,4 +14,4 @@ class ScopedDisableInternalMouseAndKeyboard {

} // namespace ash

#endif // ASH_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_
#endif // ASH_COMMON_WM_MAXIMIZE_MODE_SCOPED_DISABLE_INTERNAL_MOUSE_AND_KEYBOARD_H_
8 changes: 8 additions & 0 deletions ash/common/wm_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ WmShell* WmShell::Get() {
return instance_;
}

void WmShell::OnMaximizeModeStarted() {
FOR_EACH_OBSERVER(ShellObserver, shell_observers_, OnMaximizeModeStarted());
}

void WmShell::OnMaximizeModeEnded() {
FOR_EACH_OBSERVER(ShellObserver, shell_observers_, OnMaximizeModeEnded());
}

void WmShell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
FOR_EACH_OBSERVER(ShellObserver, shell_observers_,
OnPinnedStateChanged(pinned_window));
Expand Down
Loading

0 comments on commit e2bde21

Please sign in to comment.