Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: ash/wm/splitview/split_view_controller.h

Issue 2960843004: CrOS Tablet Window management - Split Screen part I (Closed)
Patch Set: nit. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/splitview/split_view_controller.h
diff --git a/ash/wm/splitview/split_view_controller.h b/ash/wm/splitview/split_view_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..fb4e6d371efd57e03fe82993194bb68ed227c08a
--- /dev/null
+++ b/ash/wm/splitview/split_view_controller.h
@@ -0,0 +1,135 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_
+#define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_
+
+#include "ash/ash_export.h"
+#include "ash/shell_observer.h"
+#include "ash/wm/window_state_observer.h"
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "ui/aura/window_observer.h"
+#include "ui/wm/public/activation_change_observer.h"
+
+namespace ash {
+
+class SplitViewControllerTest;
+
+// The controller for the split view. It snaps a window to left/right side of
+// the screen. It also observes the two snapped windows and decides when to exit
+// the split view mode.
+class ASH_EXPORT SplitViewController : public aura::WindowObserver,
+ public ash::wm::WindowStateObserver,
+ public ::wm::ActivationChangeObserver,
+ public ShellObserver {
+ public:
+ enum State { NO_SNAP, LEFT_SNAPPED, RIGHT_SNAPPED, BOTH_SNAPPED };
+
+ class Observer {
+ public:
+ // Called when split view state changed from |previous_state| to |state|.
+ virtual void OnSplitViewStateChanged(
+ SplitViewController::State previous_state,
+ SplitViewController::State state) {}
+ };
+
+ SplitViewController();
+ ~SplitViewController() override;
+
+ // Returns true if split view mode is supported. Currently the split view
+ // mode is only supported in maximized mode (tablet mode).
+ static bool ShouldAllowSplitView();
+
+ // Returns true if split view mode is active.
+ bool IsSplitViewModeActive() const;
+
+ // Snaps window to left/right.
+ void SetLeftWindow(aura::Window* left_window);
+ void SetRightWindow(aura::Window* right_window);
+
+ // Returns the default snapped window. It's the window that remains open until
+ // the split mode ends. It's decided by |default_snap_position_|. E.g., If
+ // |default_snap_position_| equals LEFT, then the default snapped window is
+ // |left_window_|. All the other window will open on the right side.
+ aura::Window* GetDefaultSnappedWindow();
+
+ // Gets the window bounds according to the snap state |snap_state| and the
+ // separator position |separator_position_|.
+ gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window,
+ State snap_state);
+ gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window,
+ State snap_state);
+ gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window);
+ gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window);
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // aura::WindowObserver overrides:
varkha 2017/06/30 14:29:35 nit: feel free to ignore here and below - I think
xdai1 2017/07/05 20:18:23 Done.
+ void OnWindowDestroying(aura::Window* window) override;
+
+ // ash::wm::WindowStateObserver overrides:
+ void OnPostWindowStateTypeChange(ash::wm::WindowState* window_state,
+ ash::wm::WindowStateType old_type) override;
+
+ // wm::ActivationChangeObserver:
+ void OnWindowActivated(ActivationReason reason,
+ aura::Window* gained_active,
+ aura::Window* lost_active) override;
+
+ // ShellObserver overrides:
+ void OnOverviewModeStarting() override;
+ void OnOverviewModeEnded() override;
+
+ aura::Window* left_window() { return left_window_; }
+ aura::Window* right_window() { return right_window_; }
+ int divider_position() const { return divider_position_; }
+ State state() const { return state_; }
+
+ private:
+ friend class SplitViewControllerTest;
+
+ enum DefaultSnapPosition { LEFT, RIGHT };
+
+ // Ends the split view mode.
+ void EndSplitView();
+
+ // Stops observing |window|.
+ void StopObserving(aura::Window* window);
+
+ // Notify observers that the split view state has been changed.
+ void NotifySplitViewStateChanged(State previous_state, State state);
+
+ // Gets the window bounds according to the separator position.
+ gfx::Rect GetLeftWindowBoundsInParent(aura::Window* window);
+ gfx::Rect GetRightWindowBoundsInParent(aura::Window* window);
+ gfx::Rect GetLeftWindowBoundsInScreen(aura::Window* window);
+ gfx::Rect GetRightWindowBoundsInScreen(aura::Window* window);
+
+ // The current left/right snapped window.
+ aura::Window* left_window_ = nullptr;
+ aura::Window* right_window_ = nullptr;
+
+ // The x position of the divider between |left_window_| and |right_window_| in
+ // screen coordinates.
+ int divider_position_ = -1;
+
+ // Current snap state.
+ State state_ = NO_SNAP;
+
+ // The default snap position. It's decided by the first snapped window. If the
+ // first window was snapped left, then |default_snap_position_| equals LEFT,
+ // i.e., all the other windows will open snapped on the right side - And vice
varkha 2017/06/30 14:29:35 nit: And -> and
xdai1 2017/07/05 20:18:23 Done.
+ // versa.
+ DefaultSnapPosition default_snap_position_ = LEFT;
+
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(SplitViewController);
+};
+
+} // namespace ash
+
+#endif // ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698