| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
| 6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "components/mus/public/cpp/types.h" | 13 #include "components/mus/public/cpp/types.h" |
| 14 #include "components/mus/public/interfaces/mus_constants.mojom.h" | 14 #include "components/mus/public/interfaces/mus_constants.mojom.h" |
| 15 #include "components/mus/public/interfaces/surface_id.mojom.h" | 15 #include "components/mus/public/interfaces/surface_id.mojom.h" |
| 16 #include "components/mus/public/interfaces/view_tree.mojom.h" | 16 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 17 #include "mojo/application/public/interfaces/service_provider.mojom.h" | 17 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
| 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" | 18 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" |
| 19 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" | 19 #include "third_party/mojo/src/mojo/public/cpp/system/macros.h" |
| 20 #include "ui/mojo/geometry/geometry.mojom.h" | 20 #include "ui/mojo/geometry/geometry.mojom.h" |
| 21 | 21 |
| 22 namespace mus { | 22 namespace mus { |
| 23 | 23 |
| 24 class ServiceProviderImpl; | 24 class ServiceProviderImpl; |
| 25 class WindowObserver; | 25 class WindowObserver; |
| 26 class WindowSurface; | 26 class WindowSurface; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const mojo::Rect& bounds() const { return bounds_; } | 59 const mojo::Rect& bounds() const { return bounds_; } |
| 60 void SetBounds(const mojo::Rect& bounds); | 60 void SetBounds(const mojo::Rect& bounds); |
| 61 | 61 |
| 62 const mojo::Rect& client_area() const { return client_area_; } | 62 const mojo::Rect& client_area() const { return client_area_; } |
| 63 void SetClientArea(const mojo::Rect& client_area); | 63 void SetClientArea(const mojo::Rect& client_area); |
| 64 | 64 |
| 65 // Visibility (also see IsDrawn()). When created windows are hidden. | 65 // Visibility (also see IsDrawn()). When created windows are hidden. |
| 66 bool visible() const { return visible_; } | 66 bool visible() const { return visible_; } |
| 67 void SetVisible(bool value); | 67 void SetVisible(bool value); |
| 68 | 68 |
| 69 const mojo::ViewportMetrics& viewport_metrics() { return *viewport_metrics_; } | 69 const mojom::ViewportMetrics& viewport_metrics() { |
| 70 return *viewport_metrics_; |
| 71 } |
| 70 | 72 |
| 71 scoped_ptr<WindowSurface> RequestSurface(); | 73 scoped_ptr<WindowSurface> RequestSurface(); |
| 72 | 74 |
| 73 // Returns the set of string to bag of byte properties. These properties are | 75 // Returns the set of string to bag of byte properties. These properties are |
| 74 // shared with the window manager. | 76 // shared with the window manager. |
| 75 const SharedProperties& shared_properties() const { return properties_; } | 77 const SharedProperties& shared_properties() const { return properties_; } |
| 76 // Sets a property. If |data| is null, this property is deleted. | 78 // Sets a property. If |data| is null, this property is deleted. |
| 77 void SetSharedProperty(const std::string& name, | 79 void SetSharedProperty(const std::string& name, |
| 78 const std::vector<uint8_t>* data); | 80 const std::vector<uint8_t>* data); |
| 79 | 81 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 const Window* parent() const { return parent_; } | 119 const Window* parent() const { return parent_; } |
| 118 const Children& children() const { return children_; } | 120 const Children& children() const { return children_; } |
| 119 Window* GetRoot() { | 121 Window* GetRoot() { |
| 120 return const_cast<Window*>(const_cast<const Window*>(this)->GetRoot()); | 122 return const_cast<Window*>(const_cast<const Window*>(this)->GetRoot()); |
| 121 } | 123 } |
| 122 const Window* GetRoot() const; | 124 const Window* GetRoot() const; |
| 123 | 125 |
| 124 void AddChild(Window* child); | 126 void AddChild(Window* child); |
| 125 void RemoveChild(Window* child); | 127 void RemoveChild(Window* child); |
| 126 | 128 |
| 127 void Reorder(Window* relative, mojo::OrderDirection direction); | 129 void Reorder(Window* relative, mojom::OrderDirection direction); |
| 128 void MoveToFront(); | 130 void MoveToFront(); |
| 129 void MoveToBack(); | 131 void MoveToBack(); |
| 130 | 132 |
| 131 bool Contains(Window* child) const; | 133 bool Contains(Window* child) const; |
| 132 | 134 |
| 133 Window* GetChildById(Id id); | 135 Window* GetChildById(Id id); |
| 134 | 136 |
| 135 void SetTextInputState(mojo::TextInputStatePtr state); | 137 void SetTextInputState(mojo::TextInputStatePtr state); |
| 136 void SetImeVisibility(bool visible, mojo::TextInputStatePtr state); | 138 void SetImeVisibility(bool visible, mojo::TextInputStatePtr state); |
| 137 | 139 |
| 138 // Focus. | 140 // Focus. |
| 139 void SetFocus(); | 141 void SetFocus(); |
| 140 bool HasFocus() const; | 142 bool HasFocus() const; |
| 141 | 143 |
| 142 // Embedding. See view_tree.mojom for details. | 144 // Embedding. See window_tree.mojom for details. |
| 143 void Embed(mojo::ViewTreeClientPtr client); | 145 void Embed(mus::mojom::WindowTreeClientPtr client); |
| 144 | 146 |
| 145 // NOTE: callback is run synchronously if Embed() is not allowed on this | 147 // NOTE: callback is run synchronously if Embed() is not allowed on this |
| 146 // Window. | 148 // Window. |
| 147 void Embed(mojo::ViewTreeClientPtr client, | 149 void Embed(mus::mojom::WindowTreeClientPtr client, |
| 148 uint32_t policy_bitmask, | 150 uint32_t policy_bitmask, |
| 149 const EmbedCallback& callback); | 151 const EmbedCallback& callback); |
| 150 | 152 |
| 151 protected: | 153 protected: |
| 152 // This class is subclassed only by test classes that provide a public ctor. | 154 // This class is subclassed only by test classes that provide a public ctor. |
| 153 Window(); | 155 Window(); |
| 154 ~Window(); | 156 ~Window(); |
| 155 | 157 |
| 156 private: | 158 private: |
| 157 friend class WindowPrivate; | 159 friend class WindowPrivate; |
| 158 friend class WindowTreeClientImpl; | 160 friend class WindowTreeClientImpl; |
| 159 | 161 |
| 160 Window(WindowTreeConnection* connection, Id id); | 162 Window(WindowTreeConnection* connection, Id id); |
| 161 | 163 |
| 162 // Called by the public {Set,Get,Clear}Property functions. | 164 // Called by the public {Set,Get,Clear}Property functions. |
| 163 int64_t SetLocalPropertyInternal(const void* key, | 165 int64_t SetLocalPropertyInternal(const void* key, |
| 164 const char* name, | 166 const char* name, |
| 165 PropertyDeallocator deallocator, | 167 PropertyDeallocator deallocator, |
| 166 int64_t value, | 168 int64_t value, |
| 167 int64_t default_value); | 169 int64_t default_value); |
| 168 int64_t GetLocalPropertyInternal(const void* key, | 170 int64_t GetLocalPropertyInternal(const void* key, |
| 169 int64_t default_value) const; | 171 int64_t default_value) const; |
| 170 | 172 |
| 171 void LocalDestroy(); | 173 void LocalDestroy(); |
| 172 void LocalAddChild(Window* child); | 174 void LocalAddChild(Window* child); |
| 173 void LocalRemoveChild(Window* child); | 175 void LocalRemoveChild(Window* child); |
| 174 // Returns true if the order actually changed. | 176 // Returns true if the order actually changed. |
| 175 bool LocalReorder(Window* relative, mojo::OrderDirection direction); | 177 bool LocalReorder(Window* relative, mojom::OrderDirection direction); |
| 176 void LocalSetBounds(const mojo::Rect& old_bounds, | 178 void LocalSetBounds(const mojo::Rect& old_bounds, |
| 177 const mojo::Rect& new_bounds); | 179 const mojo::Rect& new_bounds); |
| 178 void LocalSetClientArea(const mojo::Rect& new_client_area); | 180 void LocalSetClientArea(const mojo::Rect& new_client_area); |
| 179 void LocalSetViewportMetrics(const mojo::ViewportMetrics& old_metrics, | 181 void LocalSetViewportMetrics(const mojom::ViewportMetrics& old_metrics, |
| 180 const mojo::ViewportMetrics& new_metrics); | 182 const mojom::ViewportMetrics& new_metrics); |
| 181 void LocalSetDrawn(bool drawn); | 183 void LocalSetDrawn(bool drawn); |
| 182 void LocalSetVisible(bool visible); | 184 void LocalSetVisible(bool visible); |
| 183 | 185 |
| 184 // Methods implementing visibility change notifications. See WindowObserver | 186 // Methods implementing visibility change notifications. See WindowObserver |
| 185 // for more details. | 187 // for more details. |
| 186 void NotifyWindowVisibilityChanged(Window* target); | 188 void NotifyWindowVisibilityChanged(Window* target); |
| 187 // Notifies this view's observers. Returns false if |this| was deleted during | 189 // Notifies this view's observers. Returns false if |this| was deleted during |
| 188 // the call (by an observer), otherwise true. | 190 // the call (by an observer), otherwise true. |
| 189 bool NotifyWindowVisibilityChangedAtReceiver(Window* target); | 191 bool NotifyWindowVisibilityChangedAtReceiver(Window* target); |
| 190 // Notifies this view and its child hierarchy. Returns false if |this| was | 192 // Notifies this view and its child hierarchy. Returns false if |this| was |
| 191 // deleted during the call (by an observer), otherwise true. | 193 // deleted during the call (by an observer), otherwise true. |
| 192 bool NotifyWindowVisibilityChangedDown(Window* target); | 194 bool NotifyWindowVisibilityChangedDown(Window* target); |
| 193 // Notifies this view and its parent hierarchy. | 195 // Notifies this view and its parent hierarchy. |
| 194 void NotifyWindowVisibilityChangedUp(Window* target); | 196 void NotifyWindowVisibilityChangedUp(Window* target); |
| 195 | 197 |
| 196 // Returns true if embed is allowed for this node. If embedding is allowed all | 198 // Returns true if embed is allowed for this node. If embedding is allowed all |
| 197 // the children are removed. | 199 // the children are removed. |
| 198 bool PrepareForEmbed(); | 200 bool PrepareForEmbed(); |
| 199 | 201 |
| 200 WindowTreeConnection* connection_; | 202 WindowTreeConnection* connection_; |
| 201 Id id_; | 203 Id id_; |
| 202 Window* parent_; | 204 Window* parent_; |
| 203 Children children_; | 205 Children children_; |
| 204 | 206 |
| 205 base::ObserverList<WindowObserver> observers_; | 207 base::ObserverList<WindowObserver> observers_; |
| 206 | 208 |
| 207 mojo::Rect bounds_; | 209 mojo::Rect bounds_; |
| 208 mojo::Rect client_area_; | 210 mojo::Rect client_area_; |
| 209 | 211 |
| 210 mojo::ViewportMetricsPtr viewport_metrics_; | 212 mojom::ViewportMetricsPtr viewport_metrics_; |
| 211 | 213 |
| 212 bool visible_; | 214 bool visible_; |
| 213 | 215 |
| 214 SharedProperties properties_; | 216 SharedProperties properties_; |
| 215 | 217 |
| 216 // Drawn state is derived from the visible state and the parent's visible | 218 // Drawn state is derived from the visible state and the parent's visible |
| 217 // state. This field is only used if the view has no parent (eg it's a root). | 219 // state. This field is only used if the view has no parent (eg it's a root). |
| 218 bool drawn_; | 220 bool drawn_; |
| 219 | 221 |
| 220 // Value struct to keep the name and deallocator for this property. | 222 // Value struct to keep the name and deallocator for this property. |
| 221 // Key cannot be used for this purpose because it can be char* or | 223 // Key cannot be used for this purpose because it can be char* or |
| 222 // WindowProperty<>. | 224 // WindowProperty<>. |
| 223 struct Value { | 225 struct Value { |
| 224 const char* name; | 226 const char* name; |
| 225 int64_t value; | 227 int64_t value; |
| 226 PropertyDeallocator deallocator; | 228 PropertyDeallocator deallocator; |
| 227 }; | 229 }; |
| 228 | 230 |
| 229 std::map<const void*, Value> prop_map_; | 231 std::map<const void*, Value> prop_map_; |
| 230 | 232 |
| 231 MOJO_DISALLOW_COPY_AND_ASSIGN(Window); | 233 MOJO_DISALLOW_COPY_AND_ASSIGN(Window); |
| 232 }; | 234 }; |
| 233 | 235 |
| 234 } // namespace mus | 236 } // namespace mus |
| 235 | 237 |
| 236 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ | 238 #endif // COMPONENTS_MUS_PUBLIC_CPP_VIEW_H_ |
| OLD | NEW |