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

Side by Side Diff: ui/aura/window.h

Issue 82283002: Initial cut at layerless windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "ui/aura/aura_export.h" 17 #include "ui/aura/aura_export.h"
18 #include "ui/aura/client/window_types.h" 18 #include "ui/aura/client/window_types.h"
19 #include "ui/aura/window_layer_type.h"
19 #include "ui/aura/window_observer.h" 20 #include "ui/aura/window_observer.h"
20 #include "ui/compositor/layer_animator.h" 21 #include "ui/compositor/layer_animator.h"
21 #include "ui/compositor/layer_delegate.h" 22 #include "ui/compositor/layer_delegate.h"
22 #include "ui/compositor/layer_owner.h" 23 #include "ui/compositor/layer_owner.h"
23 #include "ui/compositor/layer_type.h" 24 #include "ui/compositor/layer_type.h"
24 #include "ui/events/event_constants.h" 25 #include "ui/events/event_constants.h"
25 #include "ui/events/event_target.h" 26 #include "ui/events/event_target.h"
26 #include "ui/events/gestures/gesture_types.h" 27 #include "ui/events/gestures/gesture_types.h"
27 #include "ui/gfx/insets.h" 28 #include "ui/gfx/insets.h"
28 #include "ui/gfx/native_widget_types.h" 29 #include "ui/gfx/native_widget_types.h"
29 #include "ui/gfx/rect.h" 30 #include "ui/gfx/rect.h"
30 31
31 namespace gfx { 32 namespace gfx {
32 class Display; 33 class Display;
33 class Transform; 34 class Transform;
35 class Vector2d;
34 } 36 }
35 37
36 namespace ui { 38 namespace ui {
37 class EventHandler; 39 class EventHandler;
38 class Layer; 40 class Layer;
39 class Texture; 41 class Texture;
40 } 42 }
41 43
42 namespace aura { 44 namespace aura {
43 45
(...skipping 22 matching lines...) Expand all
66 public ui::GestureConsumer { 68 public ui::GestureConsumer {
67 public: 69 public:
68 typedef std::vector<Window*> Windows; 70 typedef std::vector<Window*> Windows;
69 71
70 explicit Window(WindowDelegate* delegate); 72 explicit Window(WindowDelegate* delegate);
71 virtual ~Window(); 73 virtual ~Window();
72 74
73 // Initializes the window. This creates the window's layer. 75 // Initializes the window. This creates the window's layer.
74 void Init(ui::LayerType layer_type); 76 void Init(ui::LayerType layer_type);
75 77
78 // TODO(sky): replace other Init() with this once m32 is more baked.
79 void InitWithWindowLayerType(WindowLayerType layer_type);
80
76 // Creates a new layer for the window. Erases the layer-owned bounds, so the 81 // Creates a new layer for the window. Erases the layer-owned bounds, so the
77 // caller may wish to set new bounds and other state on the window/layer. 82 // caller may wish to set new bounds and other state on the window/layer.
78 // Returns the old layer, which can be used for animations. Caller owns the 83 // Returns the old layer, which can be used for animations. Caller owns the
79 // memory for the returned layer and must delete it when animation completes. 84 // memory for the returned layer and must delete it when animation completes.
80 // Returns NULL and does not recreate layer if window does not own its layer. 85 // Returns NULL and does not recreate layer if window does not own its layer.
81 ui::Layer* RecreateLayer() WARN_UNUSED_RESULT; 86 ui::Layer* RecreateLayer() WARN_UNUSED_RESULT;
82 87
83 void set_owned_by_parent(bool owned_by_parent) { 88 void set_owned_by_parent(bool owned_by_parent) {
84 owned_by_parent_ = owned_by_parent; 89 owned_by_parent_ = owned_by_parent;
85 } 90 }
(...skipping 13 matching lines...) Expand all
99 104
100 const base::string16 title() const { return title_; } 105 const base::string16 title() const { return title_; }
101 void set_title(const base::string16& title) { title_ = title; } 106 void set_title(const base::string16& title) { title_ = title; }
102 107
103 bool transparent() const { return transparent_; } 108 bool transparent() const { return transparent_; }
104 void SetTransparent(bool transparent); 109 void SetTransparent(bool transparent);
105 110
106 WindowDelegate* delegate() { return delegate_; } 111 WindowDelegate* delegate() { return delegate_; }
107 const WindowDelegate* delegate() const { return delegate_; } 112 const WindowDelegate* delegate() const { return delegate_; }
108 113
109 const gfx::Rect& bounds() const; 114 const gfx::Rect& bounds() const { return bounds_; }
110 115
111 Window* parent() { return parent_; } 116 Window* parent() { return parent_; }
112 const Window* parent() const { return parent_; } 117 const Window* parent() const { return parent_; }
113 118
114 // Returns the root Window that contains this Window. The root Window is 119 // Returns the root Window that contains this Window. The root Window is
115 // defined as the Window that has a dispatcher. These functions return NULL if 120 // defined as the Window that has a dispatcher. These functions return NULL if
116 // the Window is contained in a hierarchy that does not have a dispatcher at 121 // the Window is contained in a hierarchy that does not have a dispatcher at
117 // its root. 122 // its root.
118 virtual Window* GetRootWindow(); 123 virtual Window* GetRootWindow();
119 virtual const Window* GetRootWindow() const; 124 virtual const Window* GetRootWindow() const;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // are honored; otherwise, only bounds checks are performed. 404 // are honored; otherwise, only bounds checks are performed.
400 Window* GetWindowForPoint(const gfx::Point& local_point, 405 Window* GetWindowForPoint(const gfx::Point& local_point,
401 bool return_tightest, 406 bool return_tightest,
402 bool for_event_handling); 407 bool for_event_handling);
403 408
404 // Implementation of RemoveChild(). If |child| is being removed as the result 409 // Implementation of RemoveChild(). If |child| is being removed as the result
405 // of an add, |new_parent| is the new parent |child| is going to be parented 410 // of an add, |new_parent| is the new parent |child| is going to be parented
406 // to. 411 // to.
407 void RemoveChildImpl(Window* child, Window* new_parent); 412 void RemoveChildImpl(Window* child, Window* new_parent);
408 413
414 // If this Window has a layer the layer's parent is set to NULL, otherwise
415 // UnparentLayers() is invoked on all the children. |offset| is the offset
416 // relative to the nearest ancestor with a layer.
417 void UnparentLayers(bool has_layerless_ancestor,
418 const gfx::Vector2d& offset);
419
420 // If this Window has a layer it is added to |parent| and the origin set to
421 // |offset|. Otherwise this recurses through the children invoking
422 // ReparentLayers(). The net effect is both setting the parent of layers to
423 // |parent| as well as updating bounds of windows with a layerless ancestor.
424 void ReparentLayers(ui::Layer* parent, const gfx::Vector2d& offset);
425
426 // Offsets the first encountered Windows with layers by |offset|. This
427 // recurses through all layerless Windows, stopping at windows with layers.
428 void OffsetLayerBounds(const gfx::Vector2d& offset);
429
409 // Called when this window's parent has changed. 430 // Called when this window's parent has changed.
410 void OnParentChanged(); 431 void OnParentChanged();
411 432
412 // Populates |ancestors| with all transient ancestors of |window| that are 433 // Populates |ancestors| with all transient ancestors of |window| that are
413 // children of |this|. Returns true if any ancestors were found, false if not. 434 // children of |this|. Returns true if any ancestors were found, false if not.
414 bool GetAllTransientAncestors(Window* window, Windows* ancestors) const; 435 bool GetAllTransientAncestors(Window* window, Windows* ancestors) const;
415 436
416 // Replaces two windows |window1| and |window2| with their possible transient 437 // Replaces two windows |window1| and |window2| with their possible transient
417 // ancestors that are still siblings (have a common transient parent). 438 // ancestors that are still siblings (have a common transient parent).
418 // |window1| and |window2| are not modified if such ancestors cannot be found. 439 // |window1| and |window2| are not modified if such ancestors cannot be found.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 // during the call (by an observer), otherwise true. 482 // during the call (by an observer), otherwise true.
462 bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, 483 bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
463 bool visible); 484 bool visible);
464 // Notifies this window and its child hierarchy. Returns false if 485 // Notifies this window and its child hierarchy. Returns false if
465 // |this| was deleted during the call (by an observer), otherwise 486 // |this| was deleted during the call (by an observer), otherwise
466 // true. 487 // true.
467 bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible); 488 bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible);
468 // Notifies this window and its parent hierarchy. 489 // Notifies this window and its parent hierarchy.
469 void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible); 490 void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible);
470 491
471 // Invoked from the closure returned by PrepareForLayerBoundsChange() after 492 // Invoked when the bounds of the window changes. This may be invoked directly
472 // the bounds of the layer has changed. |old_bounds| is the previous bounds of 493 // by us, or from the closure returned by PrepareForLayerBoundsChange() after
473 // the layer, and |contained_mouse| is true if the mouse was previously within 494 // the bounds of the layer has changed. |old_bounds| is the previous bounds,
474 // the window's bounds. 495 // and |contained_mouse| is true if the mouse was previously within the
475 void OnLayerBoundsChanged(const gfx::Rect& old_bounds, bool contained_mouse); 496 // window's bounds.
497 void OnWindowBoundsChanged(const gfx::Rect& old_bounds, bool contained_mouse);
476 498
477 // Overridden from ui::LayerDelegate: 499 // Overridden from ui::LayerDelegate:
478 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; 500 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
479 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; 501 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
480 502
481 // Overridden from ui::EventTarget: 503 // Overridden from ui::EventTarget:
482 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; 504 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
483 virtual EventTarget* GetParentTarget() OVERRIDE; 505 virtual EventTarget* GetParentTarget() OVERRIDE;
484 506
485 // Updates the layer name with a name based on the window's name and id. 507 // Updates the layer name with a name based on the window's name and id.
486 void UpdateLayerName(const std::string& name); 508 void UpdateLayerName(const std::string& name);
487 509
488 // Returns true if the mouse is currently within our bounds. 510 // Returns true if the mouse is currently within our bounds.
489 bool ContainsMouse(); 511 bool ContainsMouse();
490 512
513 // Returns the first ancestor (starting at |this|) with a layer. |offset| is
514 // set to the offset from |this| to the first ancestor with a layer.
515 Window* GetAncestorWithLayer(gfx::Vector2d* offset) {
516 return const_cast<Window*>(
517 const_cast<const Window*>(this)->GetAncestorWithLayer(offset));
518 }
519 const Window* GetAncestorWithLayer(gfx::Vector2d* offset) const;
520
521 bool is_layerless() const { return window_layer_type_ == WINDOW_LAYER_NONE; }
Ben Goodger (Google) 2013/11/22 05:49:24 Isn't NULL-checking layer() sufficient?
sky 2013/11/22 20:20:12 I was a bit worried about a comment in the destruc
522
523 WindowLayerType window_layer_type_;
524
525 // Bounds of this window relative to the parent. This is cached as the bounds
526 // of the Layer and Window are not necessarily the same. In particular bounds
527 // of the Layer are relative to the first ancestor with a Layer, where as this
528 // is relative to the parent Window.
529 gfx::Rect bounds_;
530
491 WindowEventDispatcher* dispatcher_; 531 WindowEventDispatcher* dispatcher_;
492 532
493 client::WindowType type_; 533 client::WindowType type_;
494 534
495 // True if the Window is owned by its parent - i.e. it will be deleted by its 535 // True if the Window is owned by its parent - i.e. it will be deleted by its
496 // parent during its parents destruction. True is the default. 536 // parent during its parents destruction. True is the default.
497 bool owned_by_parent_; 537 bool owned_by_parent_;
498 538
499 WindowDelegate* delegate_; 539 WindowDelegate* delegate_;
500 540
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 }; 587 };
548 588
549 std::map<const void*, Value> prop_map_; 589 std::map<const void*, Value> prop_map_;
550 590
551 DISALLOW_COPY_AND_ASSIGN(Window); 591 DISALLOW_COPY_AND_ASSIGN(Window);
552 }; 592 };
553 593
554 } // namespace aura 594 } // namespace aura
555 595
556 #endif // UI_AURA_WINDOW_H_ 596 #endif // UI_AURA_WINDOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698