OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_AURA_WINDOW_PORT_H_ |
| 6 #define UI_AURA_WINDOW_PORT_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <string> |
| 12 |
| 13 #include "base/observer_list.h" |
| 14 #include "base/strings/string16.h" |
| 15 #include "ui/aura/aura_export.h" |
| 16 |
| 17 namespace gfx { |
| 18 class Rect; |
| 19 } |
| 20 |
| 21 namespace aura { |
| 22 |
| 23 class Window; |
| 24 class WindowObserver; |
| 25 |
| 26 // See comments in OnWillChangeProperty() for details. |
| 27 struct AURA_EXPORT WindowPortPropertyData { |
| 28 virtual ~WindowPortPropertyData() {} |
| 29 }; |
| 30 |
| 31 // See comments in Init() for details. |
| 32 struct AURA_EXPORT WindowPortInitData { |
| 33 virtual ~WindowPortInitData() {} |
| 34 }; |
| 35 |
| 36 // WindowPort defines an interface to enable Window to be used with or without |
| 37 // mus. WindowPort is owned by Window and called at key points in Windows |
| 38 // lifetime that enable Window to be used in both environments. |
| 39 // |
| 40 // If a Window is created without an explicit WindowPort then |
| 41 // Env::CreateWindowPort() is used to create the WindowPort. |
| 42 class AURA_EXPORT WindowPort { |
| 43 public: |
| 44 virtual ~WindowPort() {} |
| 45 |
| 46 // Called from Window::Init(). The return value of this is supplied to |
| 47 // OnInitDone() and is used to allow the WindowPort to pass data between the |
| 48 // two functions. |
| 49 virtual std::unique_ptr<WindowPortInitData> OnPreInit(Window* window) = 0; |
| 50 |
| 51 virtual void OnPostInit(std::unique_ptr<WindowPortInitData> data) = 0; |
| 52 |
| 53 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) = 0; |
| 54 |
| 55 // Called when a window is being added as a child. |child| may already have |
| 56 // a parent, but its parent is not the Window this WindowPort is associated |
| 57 // with. |
| 58 virtual void OnWillAddChild(Window* child) = 0; |
| 59 |
| 60 virtual void OnWillRemoveChild(Window* child) = 0; |
| 61 |
| 62 // Called to move the child at |current_index| to |dest_index|. |dest_index| |
| 63 // is calculated assuming the window at |current_index| has been removed, e.g. |
| 64 // Window* child = children_[current_index]; |
| 65 // children_.erase(children_.begin() + current_index); |
| 66 // children_.insert(children_.begin() + dest_index, child); |
| 67 virtual void OnWillMoveChild(size_t current_index, size_t dest_index) = 0; |
| 68 |
| 69 virtual void OnVisibilityChanged(bool visible) = 0; |
| 70 |
| 71 virtual void OnDidChangeBounds(const gfx::Rect& old_bounds, |
| 72 const gfx::Rect& new_bounds) = 0; |
| 73 |
| 74 // Called before a property is changed. The return value from this is supplied |
| 75 // into OnPropertyChanged() so that WindowPort may pass data between the two |
| 76 // calls. |
| 77 virtual std::unique_ptr<WindowPortPropertyData> OnWillChangeProperty( |
| 78 const void* key) = 0; |
| 79 |
| 80 // Called after a property changes, but before observers are notified. |data| |
| 81 // is the return value from OnWillChangeProperty(). |
| 82 virtual void OnPropertyChanged( |
| 83 const void* key, |
| 84 std::unique_ptr<WindowPortPropertyData> data) = 0; |
| 85 |
| 86 protected: |
| 87 // Returns the WindowPort associated with a Window. |
| 88 static WindowPort* Get(Window* window); |
| 89 |
| 90 // Returns the ObserverList of a Window. |
| 91 static base::ObserverList<WindowObserver, true>* GetObservers(Window* window); |
| 92 }; |
| 93 |
| 94 } // namespace aura |
| 95 |
| 96 #endif // UI_AURA_WINDOW_PORT_H_ |
OLD | NEW |