| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 COMPONENTS_MUS_WS_SERVER_WINDOW_H_ | |
| 6 #define COMPONENTS_MUS_WS_SERVER_WINDOW_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/logging.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/observer_list.h" | |
| 17 #include "components/mus/public/interfaces/surface.mojom.h" | |
| 18 #include "components/mus/public/interfaces/window_tree.mojom.h" | |
| 19 #include "components/mus/ws/ids.h" | |
| 20 #include "components/mus/ws/server_window_surface.h" | |
| 21 #include "mojo/public/cpp/bindings/binding.h" | |
| 22 #include "ui/gfx/geometry/insets.h" | |
| 23 #include "ui/gfx/geometry/rect.h" | |
| 24 #include "ui/gfx/geometry/vector2d.h" | |
| 25 #include "ui/gfx/transform.h" | |
| 26 #include "ui/platform_window/text_input_state.h" | |
| 27 | |
| 28 namespace mus { | |
| 29 namespace ws { | |
| 30 | |
| 31 class ServerWindowDelegate; | |
| 32 class ServerWindowObserver; | |
| 33 class ServerWindowSurfaceManager; | |
| 34 | |
| 35 // Server side representation of a window. Delegate is informed of interesting | |
| 36 // events. | |
| 37 // | |
| 38 // It is assumed that all functions that mutate the tree have validated the | |
| 39 // mutation is possible before hand. For example, Reorder() assumes the supplied | |
| 40 // window is a child and not already in position. | |
| 41 // | |
| 42 // ServerWindows do not own their children. If you delete a window that has | |
| 43 // children the children are implicitly removed. Similarly if a window has a | |
| 44 // parent and the window is deleted the deleted window is implicitly removed | |
| 45 // from the parent. | |
| 46 class ServerWindow { | |
| 47 public: | |
| 48 using Properties = std::map<std::string, std::vector<uint8_t>>; | |
| 49 using Windows = std::vector<ServerWindow*>; | |
| 50 | |
| 51 ServerWindow(ServerWindowDelegate* delegate, const WindowId& id); | |
| 52 ServerWindow(ServerWindowDelegate* delegate, | |
| 53 const WindowId& id, | |
| 54 const Properties& properties); | |
| 55 ~ServerWindow(); | |
| 56 | |
| 57 void AddObserver(ServerWindowObserver* observer); | |
| 58 void RemoveObserver(ServerWindowObserver* observer); | |
| 59 | |
| 60 // Creates a new surface of the specified type, replacing the existing. | |
| 61 void CreateSurface(mojom::SurfaceType surface_type, | |
| 62 mojo::InterfaceRequest<mojom::Surface> request, | |
| 63 mojom::SurfaceClientPtr client); | |
| 64 | |
| 65 const WindowId& id() const { return id_; } | |
| 66 | |
| 67 void Add(ServerWindow* child); | |
| 68 void Remove(ServerWindow* child); | |
| 69 void Reorder(ServerWindow* relative, mojom::OrderDirection diretion); | |
| 70 void StackChildAtBottom(ServerWindow* child); | |
| 71 void StackChildAtTop(ServerWindow* child); | |
| 72 | |
| 73 const gfx::Rect& bounds() const { return bounds_; } | |
| 74 // Sets the bounds. If the size changes this implicitly resets the client | |
| 75 // area to fill the whole bounds. | |
| 76 void SetBounds(const gfx::Rect& bounds); | |
| 77 | |
| 78 const std::vector<gfx::Rect>& additional_client_areas() const { | |
| 79 return additional_client_areas_; | |
| 80 } | |
| 81 const gfx::Insets& client_area() const { return client_area_; } | |
| 82 void SetClientArea(const gfx::Insets& insets, | |
| 83 const std::vector<gfx::Rect>& additional_client_areas); | |
| 84 | |
| 85 const gfx::Rect* hit_test_mask() const { return hit_test_mask_.get(); } | |
| 86 void SetHitTestMask(const gfx::Rect& mask); | |
| 87 void ClearHitTestMask(); | |
| 88 | |
| 89 int32_t cursor() const { return static_cast<int32_t>(cursor_id_); } | |
| 90 int32_t non_client_cursor() const { | |
| 91 return static_cast<int32_t>(non_client_cursor_id_); | |
| 92 } | |
| 93 | |
| 94 const ServerWindow* parent() const { return parent_; } | |
| 95 ServerWindow* parent() { return parent_; } | |
| 96 | |
| 97 const ServerWindow* GetRoot() const; | |
| 98 ServerWindow* GetRoot() { | |
| 99 return const_cast<ServerWindow*>( | |
| 100 const_cast<const ServerWindow*>(this)->GetRoot()); | |
| 101 } | |
| 102 | |
| 103 std::vector<const ServerWindow*> GetChildren() const; | |
| 104 std::vector<ServerWindow*> GetChildren(); | |
| 105 const Windows& children() const { return children_; } | |
| 106 | |
| 107 // Returns the ServerWindow object with the provided |id| if it lies in a | |
| 108 // subtree of |this|. | |
| 109 ServerWindow* GetChildWindow(const WindowId& id); | |
| 110 | |
| 111 // Transient window management. | |
| 112 // Adding transient child fails if the child window is modal to system. | |
| 113 bool AddTransientWindow(ServerWindow* child); | |
| 114 void RemoveTransientWindow(ServerWindow* child); | |
| 115 | |
| 116 ServerWindow* transient_parent() { return transient_parent_; } | |
| 117 const ServerWindow* transient_parent() const { return transient_parent_; } | |
| 118 | |
| 119 const Windows& transient_children() const { return transient_children_; } | |
| 120 | |
| 121 bool is_modal() const { return is_modal_; } | |
| 122 void SetModal(); | |
| 123 | |
| 124 // Returns true if this contains |window| or is |window|. | |
| 125 bool Contains(const ServerWindow* window) const; | |
| 126 | |
| 127 // Returns the visibility requested by this window. IsDrawn() returns whether | |
| 128 // the window is actually visible on screen. | |
| 129 bool visible() const { return visible_; } | |
| 130 void SetVisible(bool value); | |
| 131 | |
| 132 float opacity() const { return opacity_; } | |
| 133 void SetOpacity(float value); | |
| 134 | |
| 135 void SetPredefinedCursor(mus::mojom::Cursor cursor_id); | |
| 136 void SetNonClientCursor(mus::mojom::Cursor cursor_id); | |
| 137 | |
| 138 const gfx::Transform& transform() const { return transform_; } | |
| 139 void SetTransform(const gfx::Transform& transform); | |
| 140 | |
| 141 const std::map<std::string, std::vector<uint8_t>>& properties() const { | |
| 142 return properties_; | |
| 143 } | |
| 144 void SetProperty(const std::string& name, const std::vector<uint8_t>* value); | |
| 145 | |
| 146 std::string GetName() const; | |
| 147 | |
| 148 void SetTextInputState(const ui::TextInputState& state); | |
| 149 const ui::TextInputState& text_input_state() const { | |
| 150 return text_input_state_; | |
| 151 } | |
| 152 | |
| 153 void set_can_focus(bool can_focus) { can_focus_ = can_focus; } | |
| 154 bool can_focus() const { return can_focus_; } | |
| 155 | |
| 156 // Returns true if this window is attached to a root and all ancestors are | |
| 157 // visible. | |
| 158 bool IsDrawn() const; | |
| 159 | |
| 160 // Called when its appropriate to destroy surfaces scheduled for destruction. | |
| 161 void DestroySurfacesScheduledForDestruction(); | |
| 162 | |
| 163 const gfx::Insets& extended_hit_test_region() const { | |
| 164 return extended_hit_test_region_; | |
| 165 } | |
| 166 void set_extended_hit_test_region(const gfx::Insets& insets) { | |
| 167 extended_hit_test_region_ = insets; | |
| 168 } | |
| 169 | |
| 170 ServerWindowSurfaceManager* GetOrCreateSurfaceManager(); | |
| 171 ServerWindowSurfaceManager* surface_manager() { | |
| 172 return surface_manager_.get(); | |
| 173 } | |
| 174 const ServerWindowSurfaceManager* surface_manager() const { | |
| 175 return surface_manager_.get(); | |
| 176 } | |
| 177 | |
| 178 // Offset of the underlay from the the window bounds (used for shadows). | |
| 179 const gfx::Vector2d& underlay_offset() const { return underlay_offset_; } | |
| 180 void SetUnderlayOffset(const gfx::Vector2d& offset); | |
| 181 | |
| 182 ServerWindowDelegate* delegate() { return delegate_; } | |
| 183 | |
| 184 #if !defined(NDEBUG) | |
| 185 std::string GetDebugWindowHierarchy() const; | |
| 186 void BuildDebugInfo(const std::string& depth, std::string* result) const; | |
| 187 #endif | |
| 188 | |
| 189 private: | |
| 190 // Implementation of removing a window. Doesn't send any notification. | |
| 191 void RemoveImpl(ServerWindow* window); | |
| 192 | |
| 193 // Called when this window's stacking order among its siblings is changed. | |
| 194 void OnStackingChanged(); | |
| 195 | |
| 196 static void ReorderImpl(ServerWindow* window, | |
| 197 ServerWindow* relative, | |
| 198 mojom::OrderDirection diretion); | |
| 199 | |
| 200 // Returns a pointer to the stacking target that can be used by | |
| 201 // RestackTransientDescendants. | |
| 202 static ServerWindow** GetStackingTarget(ServerWindow* window); | |
| 203 | |
| 204 ServerWindowDelegate* delegate_; | |
| 205 const WindowId id_; | |
| 206 ServerWindow* parent_; | |
| 207 Windows children_; | |
| 208 | |
| 209 // Transient window management. | |
| 210 // If non-null we're actively restacking transient as the result of a | |
| 211 // transient ancestor changing. | |
| 212 ServerWindow* stacking_target_; | |
| 213 ServerWindow* transient_parent_; | |
| 214 Windows transient_children_; | |
| 215 | |
| 216 bool is_modal_; | |
| 217 bool visible_; | |
| 218 gfx::Rect bounds_; | |
| 219 gfx::Insets client_area_; | |
| 220 std::vector<gfx::Rect> additional_client_areas_; | |
| 221 std::unique_ptr<ServerWindowSurfaceManager> surface_manager_; | |
| 222 mojom::Cursor cursor_id_; | |
| 223 mojom::Cursor non_client_cursor_id_; | |
| 224 float opacity_; | |
| 225 bool can_focus_; | |
| 226 gfx::Transform transform_; | |
| 227 ui::TextInputState text_input_state_; | |
| 228 | |
| 229 Properties properties_; | |
| 230 | |
| 231 gfx::Vector2d underlay_offset_; | |
| 232 | |
| 233 // The hit test for windows extends outside the bounds of the window by this | |
| 234 // amount. | |
| 235 gfx::Insets extended_hit_test_region_; | |
| 236 | |
| 237 // Mouse events outside the hit test mask don't hit the window. An empty mask | |
| 238 // means all events miss the window. If null there is no mask. | |
| 239 std::unique_ptr<gfx::Rect> hit_test_mask_; | |
| 240 | |
| 241 base::ObserverList<ServerWindowObserver> observers_; | |
| 242 | |
| 243 DISALLOW_COPY_AND_ASSIGN(ServerWindow); | |
| 244 }; | |
| 245 | |
| 246 } // namespace ws | |
| 247 } // namespace mus | |
| 248 | |
| 249 #endif // COMPONENTS_MUS_WS_SERVER_WINDOW_H_ | |
| OLD | NEW |