| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 UI_AURA_WINDOW_H_ | 5 #ifndef UI_AURA_WINDOW_H_ |
| 6 #define UI_AURA_WINDOW_H_ | 6 #define UI_AURA_WINDOW_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "ui/aura/aura_export.h" | 20 #include "ui/aura/aura_export.h" |
| 21 #include "ui/aura/window_observer.h" | 21 #include "ui/aura/window_observer.h" |
| 22 #include "ui/base/class_property.h" |
| 22 #include "ui/compositor/layer_animator.h" | 23 #include "ui/compositor/layer_animator.h" |
| 23 #include "ui/compositor/layer_delegate.h" | 24 #include "ui/compositor/layer_delegate.h" |
| 24 #include "ui/compositor/layer_owner.h" | 25 #include "ui/compositor/layer_owner.h" |
| 25 #include "ui/events/event_constants.h" | 26 #include "ui/events/event_constants.h" |
| 26 #include "ui/events/event_target.h" | 27 #include "ui/events/event_target.h" |
| 27 #include "ui/events/event_targeter.h" | 28 #include "ui/events/event_targeter.h" |
| 28 #include "ui/events/gestures/gesture_types.h" | 29 #include "ui/events/gestures/gesture_types.h" |
| 29 #include "ui/gfx/geometry/insets.h" | 30 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
| 31 #include "ui/gfx/native_widget_types.h" | 32 #include "ui/gfx/native_widget_types.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 } | 45 } |
| 45 | 46 |
| 46 namespace aura { | 47 namespace aura { |
| 47 | 48 |
| 48 class LayoutManager; | 49 class LayoutManager; |
| 49 class WindowDelegate; | 50 class WindowDelegate; |
| 50 class WindowPort; | 51 class WindowPort; |
| 51 class WindowObserver; | 52 class WindowObserver; |
| 52 class WindowTreeHost; | 53 class WindowTreeHost; |
| 53 | 54 |
| 54 // Defined in window_property.h (which we do not include) | 55 // Defined in class_property.h (which we do not include) |
| 55 template<typename T> | 56 template<typename T> |
| 56 struct WindowProperty; | 57 using WindowProperty = ui::ClassProperty<T>; |
| 57 | |
| 58 namespace subtle { | |
| 59 class PropertyHelper; | |
| 60 } | |
| 61 | 58 |
| 62 namespace test { | 59 namespace test { |
| 63 class WindowTestApi; | 60 class WindowTestApi; |
| 64 } | 61 } |
| 65 | 62 |
| 66 // Aura window implementation. Interesting events are sent to the | 63 // Aura window implementation. Interesting events are sent to the |
| 67 // WindowDelegate. | 64 // WindowDelegate. |
| 68 // TODO(beng): resolve ownership. | 65 // TODO(beng): resolve ownership. |
| 69 class AURA_EXPORT Window : public ui::LayerDelegate, | 66 class AURA_EXPORT Window : public ui::LayerDelegate, |
| 70 public ui::LayerOwner, | 67 public ui::LayerOwner, |
| 71 public ui::EventTarget, | 68 public ui::EventTarget, |
| 72 public ui::GestureConsumer { | 69 public ui::GestureConsumer, |
| 70 public ui::PropertyHandler { |
| 73 public: | 71 public: |
| 74 // Initial value of id() for newly created windows. | 72 // Initial value of id() for newly created windows. |
| 75 static constexpr int kInitialId = -1; | 73 static constexpr int kInitialId = -1; |
| 76 | 74 |
| 77 // Used when stacking windows. | 75 // Used when stacking windows. |
| 78 enum StackDirection { | 76 enum StackDirection { |
| 79 STACK_ABOVE, | 77 STACK_ABOVE, |
| 80 STACK_BELOW | 78 STACK_BELOW |
| 81 }; | 79 }; |
| 82 | 80 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 void ReleaseCapture(); | 283 void ReleaseCapture(); |
| 286 | 284 |
| 287 // Returns true if this window has capture. | 285 // Returns true if this window has capture. |
| 288 bool HasCapture(); | 286 bool HasCapture(); |
| 289 | 287 |
| 290 // Suppresses painting window content by disgarding damaged rect and ignoring | 288 // Suppresses painting window content by disgarding damaged rect and ignoring |
| 291 // new paint requests. This is a one way operation and there is no way to | 289 // new paint requests. This is a one way operation and there is no way to |
| 292 // reenable painting. | 290 // reenable painting. |
| 293 void SuppressPaint(); | 291 void SuppressPaint(); |
| 294 | 292 |
| 295 // Sets the |value| of the given window |property|. Setting to the default | |
| 296 // value (e.g., NULL) removes the property. The caller is responsible for the | |
| 297 // lifetime of any object set as a property on the Window. | |
| 298 template<typename T> | |
| 299 void SetProperty(const WindowProperty<T>* property, T value); | |
| 300 | |
| 301 // Returns the value of the given window |property|. Returns the | |
| 302 // property-specific default value if the property was not previously set. | |
| 303 template<typename T> | |
| 304 T GetProperty(const WindowProperty<T>* property) const; | |
| 305 | |
| 306 // Sets the |property| to its default value. Useful for avoiding a cast when | |
| 307 // setting to NULL. | |
| 308 template<typename T> | |
| 309 void ClearProperty(const WindowProperty<T>* property); | |
| 310 | |
| 311 // Returns the value of all properties with a non-default value. | |
| 312 std::set<const void*> GetAllPropertKeys() const; | |
| 313 | |
| 314 // NativeWidget::[GS]etNativeWindowProperty use strings as keys, and this is | 293 // NativeWidget::[GS]etNativeWindowProperty use strings as keys, and this is |
| 315 // difficult to change while retaining compatibility with other platforms. | 294 // difficult to change while retaining compatibility with other platforms. |
| 316 // TODO(benrg): Find a better solution. | 295 // TODO(benrg): Find a better solution. |
| 317 void SetNativeWindowProperty(const char* key, void* value); | 296 void SetNativeWindowProperty(const char* key, void* value); |
| 318 void* GetNativeWindowProperty(const char* key) const; | 297 void* GetNativeWindowProperty(const char* key) const; |
| 319 | 298 |
| 320 // Type of a function to delete a property that this window owns. | 299 // Type of a function to delete a property that this window owns. |
| 321 typedef void (*PropertyDeallocator)(int64_t value); | 300 //typedef void (*PropertyDeallocator)(int64_t value); |
| 322 | 301 |
| 323 // Overridden from ui::LayerDelegate: | 302 // Overridden from ui::LayerDelegate: |
| 324 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 303 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
| 325 | 304 |
| 326 #if !defined(NDEBUG) | 305 #if !defined(NDEBUG) |
| 327 // These methods are useful when debugging. | 306 // These methods are useful when debugging. |
| 328 std::string GetDebugInfo() const; | 307 std::string GetDebugInfo() const; |
| 329 void PrintWindowHierarchy(int depth) const; | 308 void PrintWindowHierarchy(int depth) const; |
| 330 #endif | 309 #endif |
| 331 | 310 |
| 332 // Returns true if there was state needing to be cleaned up. | 311 // Returns true if there was state needing to be cleaned up. |
| 333 bool CleanupGestureState(); | 312 bool CleanupGestureState(); |
| 334 | 313 |
| 335 protected: | 314 protected: |
| 336 // Deletes (or removes if not owned by parent) all child windows. Intended for | 315 // Deletes (or removes if not owned by parent) all child windows. Intended for |
| 337 // use from the destructor. | 316 // use from the destructor. |
| 338 void RemoveOrDestroyChildren(); | 317 void RemoveOrDestroyChildren(); |
| 339 | 318 |
| 319 // Overrides from ui::PropertyHandler |
| 320 std::unique_ptr<ui::PropertyData> BeforePropertyChange(const void* key) |
| 321 override; |
| 322 void AfterPropertyChange(const void* key, |
| 323 int64_t old_value, |
| 324 std::unique_ptr<ui::PropertyData> data) override; |
| 340 private: | 325 private: |
| 341 friend class LayoutManager; | 326 friend class LayoutManager; |
| 342 friend class PropertyConverter; | 327 friend class PropertyConverter; |
| 343 friend class WindowPort; | 328 friend class WindowPort; |
| 344 friend class WindowTargeter; | 329 friend class WindowTargeter; |
| 345 friend class subtle::PropertyHelper; | |
| 346 friend class test::WindowTestApi; | 330 friend class test::WindowTestApi; |
| 347 | 331 |
| 348 // Called by the public {Set,Get,Clear}Property functions. | |
| 349 int64_t SetPropertyInternal(const void* key, | |
| 350 const char* name, | |
| 351 PropertyDeallocator deallocator, | |
| 352 int64_t value, | |
| 353 int64_t default_value); | |
| 354 int64_t GetPropertyInternal(const void* key, int64_t default_value) const; | |
| 355 | |
| 356 // Returns true if the mouse pointer at relative-to-this-Window's-origin | 332 // Returns true if the mouse pointer at relative-to-this-Window's-origin |
| 357 // |local_point| can trigger an event for this Window. | 333 // |local_point| can trigger an event for this Window. |
| 358 // TODO(beng): A Window can supply a hit-test mask to cause some portions of | 334 // TODO(beng): A Window can supply a hit-test mask to cause some portions of |
| 359 // itself to not trigger events, causing the events to fall through to the | 335 // itself to not trigger events, causing the events to fall through to the |
| 360 // Window behind. | 336 // Window behind. |
| 361 bool HitTest(const gfx::Point& local_point); | 337 bool HitTest(const gfx::Point& local_point); |
| 362 | 338 |
| 363 // Changes the bounds of the window without condition. | 339 // Changes the bounds of the window without condition. |
| 364 void SetBoundsInternal(const gfx::Rect& new_bounds); | 340 void SetBoundsInternal(const gfx::Rect& new_bounds); |
| 365 | 341 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 std::unique_ptr<ui::EventTargeter> targeter_; | 480 std::unique_ptr<ui::EventTargeter> targeter_; |
| 505 | 481 |
| 506 // Makes the window pass all events through to any windows behind it. | 482 // Makes the window pass all events through to any windows behind it. |
| 507 bool ignore_events_; | 483 bool ignore_events_; |
| 508 | 484 |
| 509 // See set_hit_test_bounds_override_inner(). | 485 // See set_hit_test_bounds_override_inner(). |
| 510 gfx::Insets hit_test_bounds_override_inner_; | 486 gfx::Insets hit_test_bounds_override_inner_; |
| 511 | 487 |
| 512 base::ObserverList<WindowObserver, true> observers_; | 488 base::ObserverList<WindowObserver, true> observers_; |
| 513 | 489 |
| 514 // Value struct to keep the name and deallocator for this property. | |
| 515 // Key cannot be used for this purpose because it can be char* or | |
| 516 // WindowProperty<>. | |
| 517 struct Value { | |
| 518 const char* name; | |
| 519 int64_t value; | |
| 520 PropertyDeallocator deallocator; | |
| 521 }; | |
| 522 | |
| 523 std::map<const void*, Value> prop_map_; | |
| 524 | |
| 525 DISALLOW_COPY_AND_ASSIGN(Window); | 490 DISALLOW_COPY_AND_ASSIGN(Window); |
| 526 }; | 491 }; |
| 527 | 492 |
| 528 } // namespace aura | 493 } // namespace aura |
| 529 | 494 |
| 530 #endif // UI_AURA_WINDOW_H_ | 495 #endif // UI_AURA_WINDOW_H_ |
| OLD | NEW |