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" 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/aura/window_layer_type.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window_observer.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animator.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_delegate.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_owner.h" 23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_constants.h" 24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_target.h" 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/events/event_targeter.h" 2668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/events/gestures/gesture_types.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" 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/wm/public/window_types.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Display; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Transform; 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Vector2d; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class EventHandler; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Layer; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Texture; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace aura { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayoutManager; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowDelegate; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WindowObserver; 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class WindowTreeHost; 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Defined in window_property.h (which we do not include) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template<typename T> 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct WindowProperty; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace test { 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WindowTestApi; 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Aura window implementation. Interesting events are sent to the 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WindowDelegate. 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(beng): resolve ownership. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AURA_EXPORT Window : public ui::LayerDelegate, 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ui::LayerOwner, 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ui::EventTarget, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ui::GestureConsumer { 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Used when stacking windows. 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) enum StackDirection { 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STACK_ABOVE, 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STACK_BELOW 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<Window*> Windows; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Window(WindowDelegate* delegate); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Window(); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes the window. This creates the window's layer. 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void Init(WindowLayerType layer_type); 80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_owned_by_parent(bool owned_by_parent) { 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) owned_by_parent_ = owned_by_parent; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool owned_by_parent() const { return owned_by_parent_; } 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A type is used to identify a class of Windows and customize behavior such 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // as event handling and parenting. This field should only be consumed by the 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shell -- Aura itself shouldn't contain type-specific logic. 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::wm::WindowType type() const { return type_; } 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetType(ui::wm::WindowType type); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int id() const { return id_; } 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_id(int id) { id_ = id; } 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& name() const { return name_; } 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetName(const std::string& name); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::string16 title() const { return title_; } 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void SetTitle(const base::string16& title); 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool transparent() const { return transparent_; } 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetTransparent(bool transparent); 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 104effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // See description in Layer::SetFillsBoundsCompletely. 105effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch void SetFillsBoundsCompletely(bool fills_bounds); 106effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowDelegate* delegate() { return delegate_; } 1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const WindowDelegate* delegate() const { return delegate_; } 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const gfx::Rect& bounds() const { return bounds_; } 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* parent() { return parent_; } 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Window* parent() const { return parent_; } 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns the root Window that contains this Window. The root Window is 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // defined as the Window that has a dispatcher. These functions return NULL if 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the Window is contained in a hierarchy that does not have a dispatcher at 1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // its root. 1195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu Window* GetRootWindow(); 1205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const Window* GetRootWindow() const; 1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowTreeHost* GetHost(); 123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const WindowTreeHost* GetHost() const; 124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) void set_host(WindowTreeHost* host) { host_ = host; } 125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool IsRootWindow() const { return !!host_; } 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The Window does not own this object. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_user_data(void* user_data) { user_data_ = user_data; } 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* user_data() const { return user_data_; } 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the visibility of the window. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Show(); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Hide(); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this window and all its ancestors are visible. 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsVisible() const; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the visibility requested by this window. IsVisible() takes into 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // account the visibility of the layer and ancestors, where as this tracks 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // whether Show() without a Hide() has been invoked. 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool TargetVisibility() const { return visible_; } 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the window's bounds in root window's coordinates. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetBoundsInRootWindow() const; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the window's bounds in screen coordinates. 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // How the root window's coordinates is mapped to screen's coordinates 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is platform dependent and defined in the implementation of the 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |aura::client::ScreenPositionClient| interface. 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetBoundsInScreen() const; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch void SetTransform(const gfx::Transform& transform); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Assigns a LayoutManager to size and place child windows. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The Window takes ownership of the LayoutManager. 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetLayoutManager(LayoutManager* layout_manager); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayoutManager* layout_manager() { return layout_manager_.get(); } 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Sets a new event-targeter for the window, and returns the previous 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // event-targeter. 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<ui::EventTargeter> SetEventTargeter( 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<ui::EventTargeter> targeter); 161a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the bounds of the window. If present, the window's parent's 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // LayoutManager may adjust the bounds. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBounds(const gfx::Rect& new_bounds); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the bounds of the window in the screen coordintates. 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If present, the window's parent's LayoutManager may adjust the bounds. 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen_coords, 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Display& dst_display); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the target bounds of the window. If the window's layer is 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // not animating, it simply returns the current bounds. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetTargetBounds() const; 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Marks the a portion of window as needing to be painted. 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SchedulePaintInRect(const gfx::Rect& rect); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stacks the specified child of this Window at the front of the z-order. 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackChildAtTop(Window* child); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stacks |child| above |target|. Does nothing if |child| is already above 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |target|. Does not stack on top of windows with NULL layer delegates, 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // see WindowTest.StackingMadrigal for details. 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackChildAbove(Window* child, Window* target); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // Stacks the specified child of this window at the bottom of the z-order. 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void StackChildAtBottom(Window* child); 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stacks |child| below |target|. Does nothing if |child| is already below 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |target|. 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackChildBelow(Window* child, Window* target); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tree operations. 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddChild(Window* child); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveChild(Window* child); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Windows& children() const { return children_; } 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this Window contains |other| somewhere in its children. 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Contains(const Window* other) const; 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Retrieves the first-level child with the specified id, or NULL if no first- 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // level child is found matching |id|. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* GetChildById(int id); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Window* GetChildById(int id) const; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Converts |point| from |source|'s coordinates to |target|'s. If |source| is 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NULL, the function returns without modifying |point|. |target| cannot be 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NULL. 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void ConvertPointToTarget(const Window* source, 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Window* target, 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point* point); 213effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch static void ConvertRectToTarget(const Window* source, 214effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const Window* target, 215effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch gfx::Rect* rect); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moves the cursor to the specified location relative to the window. 2185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void MoveCursorTo(const gfx::Point& point_in_window); 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the cursor for the specified point, in window coordinates. 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeCursor GetCursor(const gfx::Point& point) const; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add/remove observer. 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddObserver(WindowObserver* observer); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveObserver(WindowObserver* observer); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasObserver(WindowObserver* observer); 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_ignore_events(bool ignore_events) { ignore_events_ = ignore_events; } 229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool ignore_events() const { return ignore_events_; } 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the window to grab hits for an area extending |insets| pixels inside 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // its bounds (even if that inner region overlaps a child window). This can be 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // used to create an invisible non-client area that overlaps the client area. 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_hit_test_bounds_override_inner(const gfx::Insets& insets) { 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) hit_test_bounds_override_inner_ = insets; 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Insets hit_test_bounds_override_inner() const { 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return hit_test_bounds_override_inner_; 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the |point_in_root| in root window's coordinate falls 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // within this window's bounds. Returns false if the window is detached 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from root window. 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ContainsPointInRoot(const gfx::Point& point_in_root) const; 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if relative-to-this-Window's-origin |local_point| falls 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // within this Window's bounds. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ContainsPoint(const gfx::Point& local_point) const; 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the Window that most closely encloses |local_point| for the 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // purposes of event targeting. 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* GetEventHandlerForPoint(const gfx::Point& local_point); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the topmost Window with a delegate containing |local_point|. 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* GetTopWindowContainingPoint(const gfx::Point& local_point); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns this window's toplevel window (the highest-up-the-tree anscestor 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that has a delegate set). The toplevel window may be |this|. 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* GetToplevelWindow(); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Claims or relinquishes the claim to focus. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Focus(); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Blur(); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the Window is currently the focused window. 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasFocus() const; 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the Window can be focused. 2695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool CanFocus() const; 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the Window can receive events. 2725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool CanReceiveEvents() const; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Does a capture on the window. This does nothing if the window isn't showing 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (VISIBILITY_SHOWN) or isn't contained in a valid window hierarchy. 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetCapture(); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Releases a capture. 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReleaseCapture(); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if this window has capture. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasCapture(); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Suppresses painting window content by disgarding damaged rect and ignoring 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // new paint requests. This is a one way operation and there is no way to 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // reenable painting. 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SuppressPaint(); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the |value| of the given window |property|. Setting to the default 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // value (e.g., NULL) removes the property. The caller is responsible for the 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // lifetime of any object set as a property on the Window. 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename T> 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetProperty(const WindowProperty<T>* property, T value); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the value of the given window |property|. Returns the 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // property-specific default value if the property was not previously set. 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename T> 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) T GetProperty(const WindowProperty<T>* property) const; 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the |property| to its default value. Useful for avoiding a cast when 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // setting to NULL. 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) template<typename T> 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearProperty(const WindowProperty<T>* property); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NativeWidget::[GS]etNativeWindowProperty use strings as keys, and this is 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // difficult to change while retaining compatibility with other platforms. 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(benrg): Find a better solution. 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetNativeWindowProperty(const char* key, void* value); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* GetNativeWindowProperty(const char* key) const; 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Type of a function to delete a property that this window owns. 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef void (*PropertyDeallocator)(int64 value); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from ui::LayerDelegate: 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if !defined(NDEBUG) 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These methods are useful when debugging. 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string GetDebugInfo() const; 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PrintWindowHierarchy(int depth) const; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 323c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Returns true if there was state needing to be cleaned up. 324c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool CleanupGestureState(); 325c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 3268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) protected: 3278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Deletes (or removes if not owned by parent) all child windows. Intended for 3288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // use from the destructor. 3298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void RemoveOrDestroyChildren(); 3308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class test::WindowTestApi; 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class LayoutManager; 3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) friend class WindowTargeter; 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by the public {Set,Get,Clear}Property functions. 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 SetPropertyInternal(const void* key, 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* name, 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PropertyDeallocator deallocator, 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 value, 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 default_value); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 GetPropertyInternal(const void* key, int64 default_value) const; 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns true if the mouse pointer at relative-to-this-Window's-origin 345a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // |local_point| can trigger an event for this Window. 346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // TODO(beng): A Window can supply a hit-test mask to cause some portions of 347a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // itself to not trigger events, causing the events to fall through to the 348a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Window behind. 349a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool HitTest(const gfx::Point& local_point); 350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the bounds of the window without condition. 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetBoundsInternal(const gfx::Rect& new_bounds); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the visible state of the layer, but does not make visible-state 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // specific changes. Called from Show()/Hide(). 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetVisible(bool visible); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a paint for the Window's entire bounds. 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SchedulePaint(); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 361a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Asks the delegate to paint the window and invokes PaintLayerlessChildren() 362a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // to paint any children with no layers. 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void Paint(gfx::Canvas* canvas); 364a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 365a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Paints any layerless children to |canvas|. 366a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void PaintLayerlessChildren(gfx::Canvas* canvas); 367a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets a Window (either this one or a subwindow) containing |local_point|. 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |return_tightest| is true, returns the tightest-containing (i.e. 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // furthest down the hierarchy) Window containing the point; otherwise, 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returns the loosest. If |for_event_handling| is true, then hit-test masks 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // are honored; otherwise, only bounds checks are performed. 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* GetWindowForPoint(const gfx::Point& local_point, 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool return_tightest, 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool for_event_handling); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implementation of RemoveChild(). If |child| is being removed as the result 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of an add, |new_parent| is the new parent |child| is going to be parented 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to. 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveChildImpl(Window* child, Window* new_parent); 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 382a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // If this Window has a layer the layer's parent is set to NULL, otherwise 383a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // UnparentLayers() is invoked on all the children. |offset| is the offset 384a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // relative to the nearest ancestor with a layer. 385a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void UnparentLayers(bool has_layerless_ancestor, 386a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const gfx::Vector2d& offset); 387a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 388a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // If this Window has a layer it is added to |parent| and the origin set to 389a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |offset|. Otherwise this recurses through the children invoking 390a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // ReparentLayers(). The net effect is both setting the parent of layers to 391a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |parent| as well as updating bounds of windows with a layerless ancestor. 392a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void ReparentLayers(ui::Layer* parent, const gfx::Vector2d& offset); 393a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 394a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Offsets the first encountered Windows with layers by |offset|. This 395a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // recurses through all layerless Windows, stopping at windows with layers. 396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void OffsetLayerBounds(const gfx::Vector2d& offset); 397a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when this window's parent has changed. 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnParentChanged(); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The various stacking functions call into this to do the actual stacking. 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StackChildRelativeTo(Window* child, 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* target, 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StackDirection direction); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Invoked from StackChildRelativeTo() to stack the layers appropriately 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // when stacking |child| relative to |target|. 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void StackChildLayerRelativeTo(Window* child, 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Window* target, 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StackDirection direction); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when this window's stacking order among its siblings is changed. 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnStackingChanged(); 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notifies observers registered with this Window (and its subtree) when the 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Window has been added or is about to be removed from a RootWindow. 417effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch void NotifyRemovingFromRootWindow(Window* new_root); 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyAddedToRootWindow(); 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Methods implementing hierarchy change notifications. See WindowObserver for 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // more details. 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowHierarchyChange( 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const WindowObserver::HierarchyChangeParams& params); 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window and its child hierarchy. 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowHierarchyChangeDown( 4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const WindowObserver::HierarchyChangeParams& params); 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window and its parent hierarchy. 4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowHierarchyChangeUp( 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const WindowObserver::HierarchyChangeParams& params); 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window's observers. 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowHierarchyChangeAtReceiver( 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const WindowObserver::HierarchyChangeParams& params); 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Methods implementing visibility change notifications. See WindowObserver 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // for more details. 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowVisibilityChanged(aura::Window* target, bool visible); 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window's observers. Returns false if |this| was deleted 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // during the call (by an observer), otherwise true. 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool visible); 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window and its child hierarchy. Returns false if 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |this| was deleted during the call (by an observer), otherwise 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // true. 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool NotifyWindowVisibilityChangedDown(aura::Window* target, bool visible); 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Notifies this window and its parent hierarchy. 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyWindowVisibilityChangedUp(aura::Window* target, bool visible); 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Notifies this window and its child hierarchy of a transform applied to 4491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // |source|. 4501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void NotifyAncestorWindowTransformed(Window* source); 4511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 452a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Invoked when the bounds of the window changes. This may be invoked directly 453a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // by us, or from the closure returned by PrepareForLayerBoundsChange() after 454effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // the bounds of the layer has changed. |old_bounds| is the previous bounds. 455effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch void OnWindowBoundsChanged(const gfx::Rect& old_bounds); 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from ui::LayerDelegate: 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; 4591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnDelegatedFrameDamage( 4601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const gfx::Rect& damage_rect_in_dip) OVERRIDE; 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Overridden from ui::EventTarget: 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual EventTarget* GetParentTarget() OVERRIDE; 466a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE; 467a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ui::EventTargeter* GetEventTargeter() OVERRIDE; 468a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void ConvertEventToTarget(ui::EventTarget* target, 469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ui::LocatedEvent* event) OVERRIDE; 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 47123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Updates the layer name based on the window's name and id. 47223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) void UpdateLayerName(); 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the mouse is currently within our bounds. 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ContainsMouse(); 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 477a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Returns the first ancestor (starting at |this|) with a layer. |offset| is 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // set to the offset from |this| to the first ancestor with a layer. |offset| 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // may be NULL. 480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Window* GetAncestorWithLayer(gfx::Vector2d* offset) { 481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return const_cast<Window*>( 482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const_cast<const Window*>(this)->GetAncestorWithLayer(offset)); 483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const Window* GetAncestorWithLayer(gfx::Vector2d* offset) const; 485a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Bounds of this window relative to the parent. This is cached as the bounds 487a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // of the Layer and Window are not necessarily the same. In particular bounds 488a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // of the Layer are relative to the first ancestor with a Layer, where as this 489a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // is relative to the parent Window. 490a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect bounds_; 491a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 492a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) WindowTreeHost* host_; 4931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::wm::WindowType type_; 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the Window is owned by its parent - i.e. it will be deleted by its 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // parent during its parents destruction. True is the default. 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool owned_by_parent_; 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowDelegate* delegate_; 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The Window's parent. 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* parent_; 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Child windows. Topmost is last. 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Windows children_; 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The visibility state of the window as set by Show()/Hide(). This may differ 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from the visibility of the underlying layer, which may remain visible after 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the window is hidden (e.g. to animate its disappearance). 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool visible_; 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int id_; 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string name_; 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 516868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) base::string16 title_; 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether layer is initialized as non-opaque. 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool transparent_; 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<LayoutManager> layout_manager_; 522a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) scoped_ptr<ui::EventTargeter> targeter_; 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void* user_data_; 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Makes the window pass all events through to any windows behind it. 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ignore_events_; 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // See set_hit_test_bounds_override_inner(). 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Insets hit_test_bounds_override_inner_; 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ObserverList<WindowObserver, true> observers_; 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Value struct to keep the name and deallocator for this property. 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Key cannot be used for this purpose because it can be char* or 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WindowProperty<>. 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct Value { 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* name; 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 value; 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PropertyDeallocator deallocator; 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::map<const void*, Value> prop_map_; 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(Window); 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace aura 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_AURA_WINDOW_H_ 551