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

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: is_layerless() -> \!layer_ Created 7 years 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/event_targeter.h" 27 #include "ui/events/event_targeter.h"
27 #include "ui/events/gestures/gesture_types.h" 28 #include "ui/events/gestures/gesture_types.h"
28 #include "ui/gfx/insets.h" 29 #include "ui/gfx/insets.h"
29 #include "ui/gfx/native_widget_types.h" 30 #include "ui/gfx/native_widget_types.h"
30 #include "ui/gfx/rect.h" 31 #include "ui/gfx/rect.h"
31 32
32 namespace gfx { 33 namespace gfx {
33 class Display; 34 class Display;
34 class Transform; 35 class Transform;
36 class Vector2d;
35 } 37 }
36 38
37 namespace ui { 39 namespace ui {
38 class EventHandler; 40 class EventHandler;
39 class Layer; 41 class Layer;
40 class Texture; 42 class Texture;
41 } 43 }
42 44
43 namespace aura { 45 namespace aura {
44 46
(...skipping 22 matching lines...) Expand all
67 public ui::GestureConsumer { 69 public ui::GestureConsumer {
68 public: 70 public:
69 typedef std::vector<Window*> Windows; 71 typedef std::vector<Window*> Windows;
70 72
71 explicit Window(WindowDelegate* delegate); 73 explicit Window(WindowDelegate* delegate);
72 virtual ~Window(); 74 virtual ~Window();
73 75
74 // Initializes the window. This creates the window's layer. 76 // Initializes the window. This creates the window's layer.
75 void Init(ui::LayerType layer_type); 77 void Init(ui::LayerType layer_type);
76 78
79 // TODO(sky): replace other Init() with this once m32 is more baked.
80 void InitWithWindowLayerType(WindowLayerType layer_type);
81
77 // Creates a new layer for the window. Erases the layer-owned bounds, so the 82 // Creates a new layer for the window. Erases the layer-owned bounds, so the
78 // caller may wish to set new bounds and other state on the window/layer. 83 // caller may wish to set new bounds and other state on the window/layer.
79 // Returns the old layer, which can be used for animations. Caller owns the 84 // Returns the old layer, which can be used for animations. Caller owns the
80 // memory for the returned layer and must delete it when animation completes. 85 // memory for the returned layer and must delete it when animation completes.
81 // Returns NULL and does not recreate layer if window does not own its layer. 86 // Returns NULL and does not recreate layer if window does not own its layer.
82 ui::Layer* RecreateLayer() WARN_UNUSED_RESULT; 87 ui::Layer* RecreateLayer() WARN_UNUSED_RESULT;
83 88
84 void set_owned_by_parent(bool owned_by_parent) { 89 void set_owned_by_parent(bool owned_by_parent) {
85 owned_by_parent_ = owned_by_parent; 90 owned_by_parent_ = owned_by_parent;
86 } 91 }
(...skipping 13 matching lines...) Expand all
100 105
101 const base::string16 title() const { return title_; } 106 const base::string16 title() const { return title_; }
102 void set_title(const base::string16& title) { title_ = title; } 107 void set_title(const base::string16& title) { title_ = title; }
103 108
104 bool transparent() const { return transparent_; } 109 bool transparent() const { return transparent_; }
105 void SetTransparent(bool transparent); 110 void SetTransparent(bool transparent);
106 111
107 WindowDelegate* delegate() { return delegate_; } 112 WindowDelegate* delegate() { return delegate_; }
108 const WindowDelegate* delegate() const { return delegate_; } 113 const WindowDelegate* delegate() const { return delegate_; }
109 114
110 const gfx::Rect& bounds() const; 115 const gfx::Rect& bounds() const { return bounds_; }
111 116
112 Window* parent() { return parent_; } 117 Window* parent() { return parent_; }
113 const Window* parent() const { return parent_; } 118 const Window* parent() const { return parent_; }
114 119
115 // Returns the root Window that contains this Window. The root Window is 120 // Returns the root Window that contains this Window. The root Window is
116 // defined as the Window that has a dispatcher. These functions return NULL if 121 // defined as the Window that has a dispatcher. These functions return NULL if
117 // the Window is contained in a hierarchy that does not have a dispatcher at 122 // the Window is contained in a hierarchy that does not have a dispatcher at
118 // its root. 123 // its root.
119 virtual Window* GetRootWindow(); 124 virtual Window* GetRootWindow();
120 virtual const Window* GetRootWindow() const; 125 virtual const Window* GetRootWindow() const;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // are honored; otherwise, only bounds checks are performed. 409 // are honored; otherwise, only bounds checks are performed.
405 Window* GetWindowForPoint(const gfx::Point& local_point, 410 Window* GetWindowForPoint(const gfx::Point& local_point,
406 bool return_tightest, 411 bool return_tightest,
407 bool for_event_handling); 412 bool for_event_handling);
408 413
409 // Implementation of RemoveChild(). If |child| is being removed as the result 414 // Implementation of RemoveChild(). If |child| is being removed as the result
410 // of an add, |new_parent| is the new parent |child| is going to be parented 415 // of an add, |new_parent| is the new parent |child| is going to be parented
411 // to. 416 // to.
412 void RemoveChildImpl(Window* child, Window* new_parent); 417 void RemoveChildImpl(Window* child, Window* new_parent);
413 418
419 // If this Window has a layer the layer's parent is set to NULL, otherwise
420 // UnparentLayers() is invoked on all the children. |offset| is the offset
421 // relative to the nearest ancestor with a layer.
422 void UnparentLayers(bool has_layerless_ancestor,
423 const gfx::Vector2d& offset);
424
425 // If this Window has a layer it is added to |parent| and the origin set to
426 // |offset|. Otherwise this recurses through the children invoking
427 // ReparentLayers(). The net effect is both setting the parent of layers to
428 // |parent| as well as updating bounds of windows with a layerless ancestor.
429 void ReparentLayers(ui::Layer* parent, const gfx::Vector2d& offset);
430
431 // Offsets the first encountered Windows with layers by |offset|. This
432 // recurses through all layerless Windows, stopping at windows with layers.
433 void OffsetLayerBounds(const gfx::Vector2d& offset);
434
414 // Called when this window's parent has changed. 435 // Called when this window's parent has changed.
415 void OnParentChanged(); 436 void OnParentChanged();
416 437
417 // Populates |ancestors| with all transient ancestors of |window| that are 438 // Populates |ancestors| with all transient ancestors of |window| that are
418 // children of |this|. Returns true if any ancestors were found, false if not. 439 // children of |this|. Returns true if any ancestors were found, false if not.
419 bool GetAllTransientAncestors(Window* window, Windows* ancestors) const; 440 bool GetAllTransientAncestors(Window* window, Windows* ancestors) const;
420 441
421 // Replaces two windows |window1| and |window2| with their possible transient 442 // Replaces two windows |window1| and |window2| with their possible transient
422 // ancestors that are still siblings (have a common transient parent). 443 // ancestors that are still siblings (have a common transient parent).
423 // |window1| and |window2| are not modified if such ancestors cannot be found. 444 // |window1| and |window2| are not modified if such ancestors cannot be found.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // during the call (by an observer), otherwise true. 487 // during the call (by an observer), otherwise true.
467 bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, 488 bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
468 bool visible); 489 bool visible);
469 // Notifies this window and its child hierarchy. Returns false if 490 // Notifies this window and its child hierarchy. Returns false if
470 // |this| was deleted during the call (by an observer), otherwise 491 // |this| was deleted during the call (by an observer), otherwise
471 // true. 492 // true.
472 bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible); 493 bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible);
473 // Notifies this window and its parent hierarchy. 494 // Notifies this window and its parent hierarchy.
474 void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible); 495 void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible);
475 496
476 // Invoked from the closure returned by PrepareForLayerBoundsChange() after 497 // Invoked when the bounds of the window changes. This may be invoked directly
477 // the bounds of the layer has changed. |old_bounds| is the previous bounds of 498 // by us, or from the closure returned by PrepareForLayerBoundsChange() after
478 // the layer, and |contained_mouse| is true if the mouse was previously within 499 // the bounds of the layer has changed. |old_bounds| is the previous bounds,
479 // the window's bounds. 500 // and |contained_mouse| is true if the mouse was previously within the
480 void OnLayerBoundsChanged(const gfx::Rect& old_bounds, bool contained_mouse); 501 // window's bounds.
502 void OnWindowBoundsChanged(const gfx::Rect& old_bounds, bool contained_mouse);
481 503
482 // Overridden from ui::LayerDelegate: 504 // Overridden from ui::LayerDelegate:
483 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; 505 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
484 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; 506 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
485 507
486 // Overridden from ui::EventTarget: 508 // Overridden from ui::EventTarget:
487 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; 509 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
488 virtual EventTarget* GetParentTarget() OVERRIDE; 510 virtual EventTarget* GetParentTarget() OVERRIDE;
489 virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE; 511 virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE;
490 virtual ui::EventTargeter* GetEventTargeter() OVERRIDE; 512 virtual ui::EventTargeter* GetEventTargeter() OVERRIDE;
491 virtual void ConvertEventToTarget(ui::EventTarget* target, 513 virtual void ConvertEventToTarget(ui::EventTarget* target,
492 ui::LocatedEvent* event) OVERRIDE; 514 ui::LocatedEvent* event) OVERRIDE;
493 515
494 // Updates the layer name with a name based on the window's name and id. 516 // Updates the layer name with a name based on the window's name and id.
495 void UpdateLayerName(const std::string& name); 517 void UpdateLayerName(const std::string& name);
496 518
497 // Returns true if the mouse is currently within our bounds. 519 // Returns true if the mouse is currently within our bounds.
498 bool ContainsMouse(); 520 bool ContainsMouse();
499 521
522 // Returns the first ancestor (starting at |this|) with a layer. |offset| is
523 // set to the offset from |this| to the first ancestor with a layer.
524 Window* GetAncestorWithLayer(gfx::Vector2d* offset) {
525 return const_cast<Window*>(
526 const_cast<const Window*>(this)->GetAncestorWithLayer(offset));
527 }
528 const Window* GetAncestorWithLayer(gfx::Vector2d* offset) const;
529
530 // Bounds of this window relative to the parent. This is cached as the bounds
531 // of the Layer and Window are not necessarily the same. In particular bounds
532 // of the Layer are relative to the first ancestor with a Layer, where as this
533 // is relative to the parent Window.
534 gfx::Rect bounds_;
535
500 WindowEventDispatcher* dispatcher_; 536 WindowEventDispatcher* dispatcher_;
501 537
502 client::WindowType type_; 538 client::WindowType type_;
503 539
504 // True if the Window is owned by its parent - i.e. it will be deleted by its 540 // True if the Window is owned by its parent - i.e. it will be deleted by its
505 // parent during its parents destruction. True is the default. 541 // parent during its parents destruction. True is the default.
506 bool owned_by_parent_; 542 bool owned_by_parent_;
507 543
508 WindowDelegate* delegate_; 544 WindowDelegate* delegate_;
509 545
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 }; 593 };
558 594
559 std::map<const void*, Value> prop_map_; 595 std::map<const void*, Value> prop_map_;
560 596
561 DISALLOW_COPY_AND_ASSIGN(Window); 597 DISALLOW_COPY_AND_ASSIGN(Window);
562 }; 598 };
563 599
564 } // namespace aura 600 } // namespace aura
565 601
566 #endif // UI_AURA_WINDOW_H_ 602 #endif // UI_AURA_WINDOW_H_
OLDNEW
« no previous file with comments | « ui/aura/aura.gyp ('k') | ui/aura/window.cc » ('j') | ui/aura/window.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698