window.h revision 5e3f23d412006dc4db4e659864679f29341e113f
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_AURA_WINDOW_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_AURA_WINDOW_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h"
165e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string16.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/aura_export.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_types.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window_observer.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/events/event_constants.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/events/event_target.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/gestures/gesture_types.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animator.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_delegate.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_owner.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_type.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/insets.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Display;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Transform;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui {
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class EventHandler;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Layer;
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Texture;
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace aura {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayoutManager;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RootWindow;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowDelegate;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowObserver;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Defined in window_property.h (which we do not include)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template<typename T>
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WindowProperty;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test {
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WindowTestApi;
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Aura window implementation. Interesting events are sent to the
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WindowDelegate.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(beng): resolve ownership.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AURA_EXPORT Window : public ui::LayerDelegate,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           public ui::LayerOwner,
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           public ui::EventTarget,
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           public ui::GestureConsumer {
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef std::vector<Window*> Windows;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit Window(WindowDelegate* delegate);
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Window();
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initializes the window. This creates the window's layer.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Init(ui::LayerType layer_type);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Creates a new layer for the window. Erases the layer-owned bounds, so the
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // caller may wish to set new bounds and other state on the window/layer.
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the old layer, which can be used for animations. Caller owns the
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // memory for the returned layer and must delete it when animation completes.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns NULL and does not recreate layer if window does not own its layer.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ui::Layer* RecreateLayer() WARN_UNUSED_RESULT;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_owned_by_parent(bool owned_by_parent) {
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    owned_by_parent_ = owned_by_parent;
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A type is used to identify a class of Windows and customize behavior such
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // as event handling and parenting.  This field should only be consumed by the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // shell -- Aura itself shouldn't contain type-specific logic.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  client::WindowType type() const { return type_; }
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetType(client::WindowType type);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int id() const { return id_; }
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_id(int id) { id_ = id; }
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& name() const { return name_; }
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetName(const std::string& name);
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const base::string16 title() const { return title_; }
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void set_title(const base::string16& title) { title_ = title; }
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool transparent() const { return transparent_; }
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetTransparent(bool transparent);
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WindowDelegate* delegate() { return delegate_; }
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const gfx::Rect& bounds() const;
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* parent() { return parent_; }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Window* parent() const { return parent_; }
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the RootWindow that contains this Window or NULL if the Window is
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not contained by a RootWindow.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual RootWindow* GetRootWindow();
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual const RootWindow* GetRootWindow() const;
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The Window does not own this object.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_user_data(void* user_data) { user_data_ = user_data; }
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void* user_data() const { return user_data_; }
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the visibility of the window.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Show();
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Hide();
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this window and all its ancestors are visible.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsVisible() const;
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the visibility requested by this window. IsVisible() takes into
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // account the visibility of the layer and ancestors, where as this tracks
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // whether Show() without a Hide() has been invoked.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool TargetVisibility() const { return visible_; }
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the window's bounds in root window's coordinates.
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect GetBoundsInRootWindow() const;
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the window's bounds in screen coordinates.
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // How the root window's coordinates is mapped to screen's coordinates
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is platform dependent and defined in the implementation of the
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |aura::client::ScreenPositionClient| interface.
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect GetBoundsInScreen() const;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetTransform(const gfx::Transform& transform);
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Assigns a LayoutManager to size and place child windows.
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The Window takes ownership of the LayoutManager.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetLayoutManager(LayoutManager* layout_manager);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LayoutManager* layout_manager() { return layout_manager_.get(); }
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the bounds of the window. If present, the window's parent's
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // LayoutManager may adjust the bounds.
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBounds(const gfx::Rect& new_bounds);
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the bounds of the window in the screen coordintates.
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If present, the window's parent's LayoutManager may adjust the bounds.
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords,
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const gfx::Display& dst_display);
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the target bounds of the window. If the window's layer is
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not animating, it simply returns the current bounds.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Rect GetTargetBounds() const;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Marks the a portion of window as needing to be painted.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SchedulePaintInRect(const gfx::Rect& rect);
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Places this window per |root_window|'s stacking client. The final location
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // may be a RootWindow other than the one passed in. |root_window| may not be
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // NULL. |bounds_in_screen| may be empty; it is more optional context that
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // may, but isn't necessarily used.
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetDefaultParentByRootWindow(RootWindow* root_window,
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                    const gfx::Rect& bounds_in_screen);
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks the specified child of this Window at the front of the z-order.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackChildAtTop(Window* child);
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| above |target|.  Does nothing if |child| is already above
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |target|.  Does not stack on top of windows with NULL layer delegates,
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // see WindowTest.StackingMadrigal for details.
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackChildAbove(Window* child, Window* target);
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Stacks the specified child of this window at the bottom of the z-order.
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  void StackChildAtBottom(Window* child);
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Stacks |child| below |target|. Does nothing if |child| is already below
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |target|.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackChildBelow(Window* child, Window* target);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Tree operations.
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddChild(Window* child);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveChild(Window* child);
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Windows& children() const { return children_; }
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this Window contains |other| somewhere in its children.
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Contains(const Window* other) const;
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adds or removes |child| as a transient child of this window. Transient
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // children get the following behavior:
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // . The transient parent destroys any transient children when it is
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   destroyed. This means a transient child is destroyed if either its parent
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   or transient parent is destroyed.
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // . If a transient child and its transient parent share the same parent, then
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //   transient children are always ordered above the transient parent.
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Transient windows are typically used for popups and menus.
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddTransientChild(Window* child);
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveTransientChild(Window* child);
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Windows& transient_children() const { return transient_children_; }
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* transient_parent() { return transient_parent_; }
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Window* transient_parent() const { return transient_parent_; }
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Retrieves the first-level child with the specified id, or NULL if no first-
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // level child is found matching |id|.
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* GetChildById(int id);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Window* GetChildById(int id) const;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Converts |point| from |source|'s coordinates to |target|'s. If |source| is
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NULL, the function returns without modifying |point|. |target| cannot be
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NULL.
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void ConvertPointToTarget(const Window* source,
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const Window* target,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   gfx::Point* point);
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Moves the cursor to the specified location relative to the window.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void MoveCursorTo(const gfx::Point& point_in_window);
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the cursor for the specified point, in window coordinates.
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::NativeCursor GetCursor(const gfx::Point& point) const;
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Sets an 'event filter' for the window. An 'event filter' for a Window is
2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // a pre-target event handler, where the window owns the handler. A window
2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // can have only one such event filter. Setting a new filter removes and
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // destroys any previously installed filter.
2292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void SetEventFilter(ui::EventHandler* event_filter);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add/remove observer.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void AddObserver(WindowObserver* observer);
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveObserver(WindowObserver* observer);
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasObserver(WindowObserver* observer);
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; }
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Sets the window to grab hits for mouse and touch to an area extending
239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // -|mouse_insets| and -|touch_insets| pixels outside its bounds. This can be
240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // used to create an invisible non-client area, for example if your windows
241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // have no visible frames but still need to have resize edges.
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetHitTestBoundsOverrideOuter(const gfx::Insets& mouse_insets,
243c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                     const gfx::Insets& touch_insets) {
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    hit_test_bounds_override_outer_mouse_ = mouse_insets;
245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    hit_test_bounds_override_outer_touch_ = touch_insets;
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets hit_test_bounds_override_outer_mouse() const {
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return hit_test_bounds_override_outer_mouse_;
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the window to grab hits for an area extending |insets| pixels inside
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // its bounds (even if that inner region overlaps a child window). This can be
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // used to create an invisible non-client area that overlaps the client area.
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void set_hit_test_bounds_override_inner(const gfx::Insets& insets) {
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    hit_test_bounds_override_inner_ = insets;
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets hit_test_bounds_override_inner() const {
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return hit_test_bounds_override_inner_;
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the |point_in_root| in root window's coordinate falls
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // within this window's bounds. Returns false if the window is detached
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from root window.
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ContainsPointInRoot(const gfx::Point& point_in_root) const;
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if relative-to-this-Window's-origin |local_point| falls
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // within this Window's bounds.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ContainsPoint(const gfx::Point& local_point) const;
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the mouse pointer at relative-to-this-Window's-origin
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |local_point| can trigger an event for this Window.
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): A Window can supply a hit-test mask to cause some portions of
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // itself to not trigger events, causing the events to fall through to the
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Window behind.
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HitTest(const gfx::Point& local_point);
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the Window that most closely encloses |local_point| for the
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // purposes of event targeting.
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* GetEventHandlerForPoint(const gfx::Point& local_point);
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the topmost Window with a delegate containing |local_point|.
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* GetTopWindowContainingPoint(const gfx::Point& local_point);
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns this window's toplevel window (the highest-up-the-tree anscestor
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that has a delegate set).  The toplevel window may be |this|.
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* GetToplevelWindow();
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Claims or relinquishes the claim to focus.
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Focus();
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Blur();
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the Window is currently the focused window.
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasFocus() const;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the Window can be focused.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool CanFocus() const;
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the Window can receive events.
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool CanReceiveEvents() const;
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Does a capture on the window. This does nothing if the window isn't showing
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (VISIBILITY_SHOWN) or isn't contained in a valid window hierarchy.
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetCapture();
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Releases a capture.
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ReleaseCapture();
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if this window has capture.
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasCapture();
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Suppresses painting window content by disgarding damaged rect and ignoring
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new paint requests.
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SuppressPaint();
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the |value| of the given window |property|. Setting to the default
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // value (e.g., NULL) removes the property. The caller is responsible for the
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // lifetime of any object set as a property on the Window.
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename T>
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetProperty(const WindowProperty<T>* property, T value);
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the value of the given window |property|.  Returns the
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // property-specific default value if the property was not previously set.
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename T>
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  T GetProperty(const WindowProperty<T>* property) const;
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets the |property| to its default value. Useful for avoiding a cast when
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // setting to NULL.
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  template<typename T>
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ClearProperty(const WindowProperty<T>* property);
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NativeWidget::[GS]etNativeWindowProperty use strings as keys, and this is
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // difficult to change while retaining compatibility with other platforms.
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(benrg): Find a better solution.
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetNativeWindowProperty(const char* key, void* value);
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void* GetNativeWindowProperty(const char* key) const;
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Type of a function to delete a property that this window owns.
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef void (*PropertyDeallocator)(int64 value);
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ui::LayerDelegate:
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NDEBUG
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // These methods are useful when debugging.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string GetDebugInfo() const;
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void PrintWindowHierarchy(int depth) const;
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  friend class test::WindowTestApi;
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class LayoutManager;
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used when stacking windows.
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum StackDirection {
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STACK_ABOVE,
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STACK_BELOW
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called by the public {Set,Get,Clear}Property functions.
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 SetPropertyInternal(const void* key,
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const char* name,
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            PropertyDeallocator deallocator,
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int64 value,
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int64 default_value);
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int64 GetPropertyInternal(const void* key, int64 default_value) const;
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the bounds of the window without condition.
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetBoundsInternal(const gfx::Rect& new_bounds);
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the visible state of the layer, but does not make visible-state
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // specific changes. Called from Show()/Hide().
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetVisible(bool visible);
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Schedules a paint for the Window's entire bounds.
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SchedulePaint();
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a Window (either this one or a subwindow) containing |local_point|.
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |return_tightest| is true, returns the tightest-containing (i.e.
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // furthest down the hierarchy) Window containing the point; otherwise,
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returns the loosest.  If |for_event_handling| is true, then hit-test masks
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are honored; otherwise, only bounds checks are performed.
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* GetWindowForPoint(const gfx::Point& local_point,
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            bool return_tightest,
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            bool for_event_handling);
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implementation of RemoveChild(). If |child| is being removed as the result
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // of an add, |new_parent| is the new parent |child| is going to be parented
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to.
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RemoveChildImpl(Window* child, Window* new_parent);
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when this window's parent has changed.
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnParentChanged();
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Determines the real location for stacking |child| and invokes
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // StackChildRelativeToImpl().
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackChildRelativeTo(Window* child,
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            Window* target,
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            StackDirection direction);
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Implementation of StackChildRelativeTo().
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void StackChildRelativeToImpl(Window* child,
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                Window* target,
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                StackDirection direction);
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when this window's stacking order among its siblings is changed.
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnStackingChanged();
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notifies observers registered with this Window (and its subtree) when the
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Window has been added or is about to be removed from a RootWindow.
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyRemovingFromRootWindow();
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyAddedToRootWindow();
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Methods implementing hierarchy change notifications. See WindowObserver for
4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // more details.
4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowHierarchyChange(
4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const WindowObserver::HierarchyChangeParams& params);
4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window and its child hierarchy.
4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowHierarchyChangeDown(
4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const WindowObserver::HierarchyChangeParams& params);
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window and its parent hierarchy.
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowHierarchyChangeUp(
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const WindowObserver::HierarchyChangeParams& params);
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window's observers.
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowHierarchyChangeAtReceiver(
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const WindowObserver::HierarchyChangeParams& params);
4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Methods implementing visibility change notifications. See WindowObserver
4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // for more details.
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowVisibilityChanged(aura::Window* target, bool visible);
4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window's observers. Returns false if |this| was deleted
4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // during the call (by an observer), otherwise true.
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                               bool visible);
4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window and its child hierarchy. Returns false if
4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |this| was deleted during the call (by an observer), otherwise
4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // true.
4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible);
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Notifies this window and its parent hierarchy.
4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible);
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invoked from the closure returned by PrepareForLayerBoundsChange() after
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the bounds of the layer has changed. |old_bounds| is the previous bounds of
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the layer, and |contained_mouse| is true if the mouse was previously within
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the window's bounds.
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnLayerBoundsChanged(const gfx::Rect& old_bounds, bool contained_mouse);
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ui::LayerDelegate:
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE;
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ui::EventTarget:
4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual EventTarget* GetParentTarget() OVERRIDE;
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the layer name with a name based on the window's name and id.
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateLayerName(const std::string& name);
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the mouse is currently within our bounds.
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ContainsMouse();
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  client::WindowType type_;
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // True if the Window is owned by its parent - i.e. it will be deleted by its
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // parent during its parents destruction. True is the default.
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool owned_by_parent_;
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WindowDelegate* delegate_;
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The Window's parent.
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* parent_;
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Child windows. Topmost is last.
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Windows children_;
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Transient windows.
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Windows transient_children_;
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Window* transient_parent_;
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The visibility state of the window as set by Show()/Hide(). This may differ
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from the visibility of the underlying layer, which may remain visible after
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the window is hidden (e.g. to animate its disappearance).
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool visible_;
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int id_;
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string name_;
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
489868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  base::string16 title_;
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Whether layer is initialized as non-opaque.
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool transparent_;
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<ui::EventHandler> event_filter_;
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<LayoutManager> layout_manager_;
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void* user_data_;
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Makes the window pass all events through to any windows behind it.
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ignore_events_;
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // See set_hit_test_outer_override().
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets hit_test_bounds_override_outer_mouse_;
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets hit_test_bounds_override_outer_touch_;
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets hit_test_bounds_override_inner_;
5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ObserverList<WindowObserver> observers_;
5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Value struct to keep the name and deallocator for this property.
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Key cannot be used for this purpose because it can be char* or
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WindowProperty<>.
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct Value {
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const char* name;
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int64 value;
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PropertyDeallocator deallocator;
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::map<const void*, Value> prop_map_;
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(Window);
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace aura
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_AURA_WINDOW_H_
526