diff options
Diffstat (limited to 'ui/wm/public')
23 files changed, 893 insertions, 0 deletions
diff --git a/ui/wm/public/DEPS b/ui/wm/public/DEPS new file mode 100644 index 0000000..1e9f248 --- /dev/null +++ b/ui/wm/public/DEPS @@ -0,0 +1,9 @@ +include_rules = [ + "+ui/base/dragdrop/drag_drop_types.h", +] + +specific_include_rules = { + "drag_drop_client.h": [ + "+ui/base/dragdrop/drag_drop_types.h", + ], +} diff --git a/ui/wm/public/activation_change_observer.cc b/ui/wm/public/activation_change_observer.cc new file mode 100644 index 0000000..7fcbb7a --- /dev/null +++ b/ui/wm/public/activation_change_observer.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/activation_change_observer.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::ActivationChangeObserver*) + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + ActivationChangeObserver*, kActivationChangeObserverKey, NULL); + +void SetActivationChangeObserver( + Window* window, + ActivationChangeObserver* observer) { + window->SetProperty(kActivationChangeObserverKey, observer); +} + +ActivationChangeObserver* GetActivationChangeObserver(Window* window) { + return window ? window->GetProperty(kActivationChangeObserverKey) : NULL; +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/activation_change_observer.h b/ui/wm/public/activation_change_observer.h new file mode 100644 index 0000000..68d5b8a --- /dev/null +++ b/ui/wm/public/activation_change_observer.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_ACTIVATION_CHANGE_OBSERVER_H_ +#define UI_WM_PUBLIC_ACTIVATION_CHANGE_OBSERVER_H_ + +#include "ui/aura/aura_export.h" + +namespace aura { +class Window; + +namespace client { + +class AURA_EXPORT ActivationChangeObserver { + public: + // Called when |active| gains focus, or there is no active window + // (|active| is NULL in this case.) |old_active| refers to the + // previous active window or NULL if there was no previously active + // window. + virtual void OnWindowActivated(Window* gained_active, + Window* lost_active) = 0; + + // Called when during window activation the currently active window is + // selected for activation. This can happen when a window requested for + // activation cannot be activated because a system modal window is active. + virtual void OnAttemptToReactivateWindow(aura::Window* request_active, + aura::Window* actual_active) {} + + protected: + virtual ~ActivationChangeObserver() {} +}; + +// Gets/Sets the ActivationChangeObserver for a specific window. This observer +// is notified after the ActivationClient notifies all registered observers. +AURA_EXPORT void SetActivationChangeObserver( + Window* window, + ActivationChangeObserver* observer); +AURA_EXPORT ActivationChangeObserver* GetActivationChangeObserver( + Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_ACTIVATION_CHANGE_OBSERVER_H_ diff --git a/ui/wm/public/activation_client.cc b/ui/wm/public/activation_client.cc new file mode 100644 index 0000000..6a47554 --- /dev/null +++ b/ui/wm/public/activation_client.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/activation_client.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(AURA_EXPORT, aura::Window*) +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::ActivationClient*) + +namespace aura { +namespace client { + +DEFINE_WINDOW_PROPERTY_KEY( + ActivationClient*, kRootWindowActivationClientKey, NULL); +DEFINE_WINDOW_PROPERTY_KEY(bool, kHideOnDeactivate, false); + +void SetActivationClient(Window* root_window, ActivationClient* client) { + root_window->SetProperty(kRootWindowActivationClientKey, client); +} + +ActivationClient* GetActivationClient(Window* root_window) { + return root_window ? + root_window->GetProperty(kRootWindowActivationClientKey) : NULL; +} + +void SetHideOnDeactivate(Window* window, bool hide_on_deactivate) { + window->SetProperty(kHideOnDeactivate, hide_on_deactivate); +} + +bool GetHideOnDeactivate(Window* window) { + return window->GetProperty(kHideOnDeactivate); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/activation_client.h b/ui/wm/public/activation_client.h new file mode 100644 index 0000000..fc35131 --- /dev/null +++ b/ui/wm/public/activation_client.h @@ -0,0 +1,77 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_ACTIVATION_CLIENT_H_ +#define UI_WM_PUBLIC_ACTIVATION_CLIENT_H_ + +#include "ui/aura/aura_export.h" + +namespace ui { +class Event; +} + +namespace aura { +class Window; + +namespace client { +class ActivationChangeObserver; + +// An interface implemented by an object that manages window activation. +class AURA_EXPORT ActivationClient { + public: + // Adds/Removes ActivationChangeObservers. + virtual void AddObserver(ActivationChangeObserver* observer) = 0; + virtual void RemoveObserver(ActivationChangeObserver* observer) = 0; + + // Activates |window|. If |window| is NULL, nothing happens. + virtual void ActivateWindow(Window* window) = 0; + + // Deactivates |window|. What (if anything) is activated next is up to the + // client. If |window| is NULL, nothing happens. + virtual void DeactivateWindow(Window* window) = 0; + + // Retrieves the active window, or NULL if there is none. + virtual Window* GetActiveWindow() = 0; + + // Retrieves the activatable window for |window|, or NULL if there is none. + // Note that this is often but not always the toplevel window (see + // GetToplevelWindow() below), as the toplevel window may not be activatable + // (for example it may be blocked by a modal transient, or some other + // condition). + virtual Window* GetActivatableWindow(Window* window) = 0; + + // Retrieves the toplevel window for |window|, or NULL if there is none. + virtual Window* GetToplevelWindow(Window* window) = 0; + + // Invoked prior to |window| getting focus as a result of the |event|. |event| + // may be NULL. Returning false blocks |window| from getting focus. + virtual bool OnWillFocusWindow(Window* window, const ui::Event* event) = 0; + + // Returns true if |window| can be activated, false otherwise. If |window| has + // a modal child it can not be activated. + virtual bool CanActivateWindow(Window* window) const = 0; + + protected: + virtual ~ActivationClient() {} +}; + +// Sets/Gets the activation client on the root Window. +AURA_EXPORT void SetActivationClient(Window* root_window, + ActivationClient* client); +AURA_EXPORT ActivationClient* GetActivationClient(Window* root_window); + +// Some types of transient window are only visible when active. +// The transient parents of these windows may have visual appearance properties +// that differ from transient parents that can be deactivated. +// The presence of this property implies these traits. +// TODO(beng): currently the UI framework (views) implements the actual +// close-on-deactivate component of this feature but it should be +// possible to implement in the aura client. +AURA_EXPORT void SetHideOnDeactivate(Window* window, bool hide_on_deactivate); +AURA_EXPORT bool GetHideOnDeactivate(Window* window); + +} // namespace clients +} // namespace aura + +#endif // UI_WM_PUBLIC_ACTIVATION_CLIENT_H_ diff --git a/ui/wm/public/activation_delegate.cc b/ui/wm/public/activation_delegate.cc new file mode 100644 index 0000000..2a9bbc9 --- /dev/null +++ b/ui/wm/public/activation_delegate.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/activation_delegate.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::ActivationDelegate*) + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + ActivationDelegate*, kActivationDelegateKey, NULL); + +void SetActivationDelegate(Window* window, ActivationDelegate* delegate) { + window->SetProperty(kActivationDelegateKey, delegate); +} + +ActivationDelegate* GetActivationDelegate(Window* window) { + return window->GetProperty(kActivationDelegateKey); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/activation_delegate.h b/ui/wm/public/activation_delegate.h new file mode 100644 index 0000000..3c5b3ae --- /dev/null +++ b/ui/wm/public/activation_delegate.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_ACTIVATION_DELEGATE_H_ +#define UI_WM_PUBLIC_ACTIVATION_DELEGATE_H_ + +#include "ui/aura/aura_export.h" + +namespace ui { +class Event; +} + +namespace aura { +class Window; +namespace client { + +// An interface implemented by an object that configures and responds to changes +// to a window's activation state. +class AURA_EXPORT ActivationDelegate { + public: + // Returns true if the window should be activated. + virtual bool ShouldActivate() const = 0; + + protected: + virtual ~ActivationDelegate() {} +}; + +// Sets/Gets the ActivationDelegate on the Window. No ownership changes. +AURA_EXPORT void SetActivationDelegate(Window* window, + ActivationDelegate* delegate); +AURA_EXPORT ActivationDelegate* GetActivationDelegate(Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_ACTIVATION_DELEGATE_H_ diff --git a/ui/wm/public/animation_host.cc b/ui/wm/public/animation_host.cc new file mode 100644 index 0000000..0d90f9c --- /dev/null +++ b/ui/wm/public/animation_host.cc @@ -0,0 +1,28 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/animation_host.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::AnimationHost*) + +namespace aura { +namespace client { + +DEFINE_WINDOW_PROPERTY_KEY(AnimationHost*, kRootWindowAnimationHostKey, NULL); + +void SetAnimationHost(Window* window, AnimationHost* animation_host) { + DCHECK(window); + window->SetProperty(kRootWindowAnimationHostKey, animation_host); +} + +AnimationHost* GetAnimationHost(Window* window) { + DCHECK(window); + return window->GetProperty(kRootWindowAnimationHostKey); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/animation_host.h b/ui/wm/public/animation_host.h new file mode 100644 index 0000000..71f9f4d --- /dev/null +++ b/ui/wm/public/animation_host.h @@ -0,0 +1,48 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_ANIMATION_HOST_H_ +#define UI_WM_PUBLIC_ANIMATION_HOST_H_ + +#include "base/compiler_specific.h" +#include "ui/aura/aura_export.h" + +namespace gfx { +class Vector2d; +} + +namespace aura { +class Window; +namespace client { + +// Interface for top level window host of animation. Communicates additional +// bounds required for animation as well as animation completion for deferring +// window closes on hide. +class AURA_EXPORT AnimationHost { + public: + // Ensure the host window is at least this large so that transitions have + // sufficient space. + // The |top_left_delta| parameter contains the offset to be subtracted from + // the window bounds for the top left corner. + // The |bottom_right_delta| parameter contains the offset to be added to the + // window bounds for the bottom right. + virtual void SetHostTransitionOffsets( + const gfx::Vector2d& top_left_delta, + const gfx::Vector2d& bottom_right_delta) = 0; + + // Called after the window has faded out on a hide. + virtual void OnWindowHidingAnimationCompleted() = 0; + + protected: + virtual ~AnimationHost() {} +}; + +AURA_EXPORT void SetAnimationHost(Window* window, + AnimationHost* animation_host); +AURA_EXPORT AnimationHost* GetAnimationHost(Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_ANIMATION_HOST_H_ diff --git a/ui/wm/public/dispatcher_client.cc b/ui/wm/public/dispatcher_client.cc new file mode 100644 index 0000000..cec4a8a --- /dev/null +++ b/ui/wm/public/dispatcher_client.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/dispatcher_client.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::DispatcherClient*); + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY(DispatcherClient*, kDispatcherClientKey, NULL); + +void SetDispatcherClient(Window* root_window, DispatcherClient* client) { + DCHECK_EQ(root_window->GetRootWindow(), root_window); + root_window->SetProperty(kDispatcherClientKey, client); +} + +DispatcherClient* GetDispatcherClient(Window* root_window) { + if (root_window) + DCHECK_EQ(root_window->GetRootWindow(), root_window); + return root_window ? root_window->GetProperty(kDispatcherClientKey) : NULL; +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/dispatcher_client.h b/ui/wm/public/dispatcher_client.h new file mode 100644 index 0000000..9fd9c94 --- /dev/null +++ b/ui/wm/public/dispatcher_client.h @@ -0,0 +1,30 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_DISPATCHER_CLIENT_H_ +#define UI_WM_PUBLIC_DISPATCHER_CLIENT_H_ + +#include "base/message_loop/message_pump_dispatcher.h" +#include "ui/aura/aura_export.h" + +namespace aura { +class Window; +namespace client { + +// An interface implemented by an object which handles nested dispatchers. +class AURA_EXPORT DispatcherClient { + public: + virtual void RunWithDispatcher(base::MessagePumpDispatcher* dispatcher) = 0; + + virtual void QuitNestedMessageLoop() = 0; +}; + +AURA_EXPORT void SetDispatcherClient(Window* root_window, + DispatcherClient* client); +AURA_EXPORT DispatcherClient* GetDispatcherClient(Window* root_window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_DISPATCHER_CLIENT_H_ diff --git a/ui/wm/public/drag_drop_client.cc b/ui/wm/public/drag_drop_client.cc new file mode 100644 index 0000000..c452f9e --- /dev/null +++ b/ui/wm/public/drag_drop_client.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/drag_drop_client.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::DragDropClient*) + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + DragDropClient*, kRootWindowDragDropClientKey, NULL); + +void SetDragDropClient(Window* root_window, DragDropClient* client) { + DCHECK_EQ(root_window->GetRootWindow(), root_window); + root_window->SetProperty(kRootWindowDragDropClientKey, client); +} + +DragDropClient* GetDragDropClient(Window* root_window) { + if (root_window) + DCHECK_EQ(root_window->GetRootWindow(), root_window); + return root_window ? + root_window->GetProperty(kRootWindowDragDropClientKey) : NULL; +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/drag_drop_client.h b/ui/wm/public/drag_drop_client.h new file mode 100644 index 0000000..62a2355 --- /dev/null +++ b/ui/wm/public/drag_drop_client.h @@ -0,0 +1,62 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_DRAG_DROP_CLIENT_H_ +#define UI_WM_PUBLIC_DRAG_DROP_CLIENT_H_ + +#include "ui/aura/aura_export.h" +#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/gfx/native_widget_types.h" + +namespace gfx { +class Point; +} + +namespace ui { +class LocatedEvent; +class OSExchangeData; +} + +namespace aura { +class Window; +namespace client { + +// An interface implemented by an object that controls a drag and drop session. +class AURA_EXPORT DragDropClient { + public: + virtual ~DragDropClient() {} + + // Initiates a drag and drop session. Returns the drag operation that was + // applied at the end of the drag drop session. |root_location| is in the + // root Window's coordinate system. + virtual int StartDragAndDrop(const ui::OSExchangeData& data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& root_location, + int operation, + ui::DragDropTypes::DragEventSource source) = 0; + + // Called when mouse is dragged during a drag and drop. + virtual void DragUpdate(aura::Window* target, + const ui::LocatedEvent& event) = 0; + + // Called when mouse is released during a drag and drop. + virtual void Drop(aura::Window* target, + const ui::LocatedEvent& event) = 0; + + // Called when a drag and drop session is cancelled. + virtual void DragCancel() = 0; + + // Returns true if a drag and drop session is in progress. + virtual bool IsDragDropInProgress() = 0; +}; + +AURA_EXPORT void SetDragDropClient(Window* root_window, + DragDropClient* client); +AURA_EXPORT DragDropClient* GetDragDropClient(Window* root_window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_DRAG_DROP_CLIENT_H_ diff --git a/ui/wm/public/drag_drop_delegate.cc b/ui/wm/public/drag_drop_delegate.cc new file mode 100644 index 0000000..6380f96 --- /dev/null +++ b/ui/wm/public/drag_drop_delegate.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/drag_drop_delegate.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::DragDropDelegate*) + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + DragDropDelegate*, kDragDropDelegateKey, NULL); + +void SetDragDropDelegate(Window* window, DragDropDelegate* delegate) { + window->SetProperty(kDragDropDelegateKey, delegate); +} + +DragDropDelegate* GetDragDropDelegate(Window* window) { + return window->GetProperty(kDragDropDelegateKey); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/drag_drop_delegate.h b/ui/wm/public/drag_drop_delegate.h new file mode 100644 index 0000000..50f6c26 --- /dev/null +++ b/ui/wm/public/drag_drop_delegate.h @@ -0,0 +1,51 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_DRAG_DROP_DELEGATE_H_ +#define UI_WM_PUBLIC_DRAG_DROP_DELEGATE_H_ + +#include "ui/aura/aura_export.h" + +namespace ui { +class DropTargetEvent; +} + +namespace aura { +class Window; +namespace client { + +// Delegate interface for drag and drop actions on aura::Window. +class AURA_EXPORT DragDropDelegate { + public: + // OnDragEntered is invoked when the mouse enters this window during a drag & + // drop session. This is immediately followed by an invocation of + // OnDragUpdated, and eventually one of OnDragExited or OnPerformDrop. + virtual void OnDragEntered(const ui::DropTargetEvent& event) = 0; + + // Invoked during a drag and drop session while the mouse is over the window. + // This should return a bitmask of the DragDropTypes::DragOperation supported + // based on the location of the event. Return 0 to indicate the drop should + // not be accepted. + virtual int OnDragUpdated(const ui::DropTargetEvent& event) = 0; + + // Invoked during a drag and drop session when the mouse exits the window, or + // when the drag session was canceled and the mouse was over the window. + virtual void OnDragExited() = 0; + + // Invoked during a drag and drop session when OnDragUpdated returns a valid + // operation and the user release the mouse. + virtual int OnPerformDrop(const ui::DropTargetEvent& event) = 0; + + protected: + virtual ~DragDropDelegate() {} +}; + +AURA_EXPORT void SetDragDropDelegate(Window* window, + DragDropDelegate* delegate); +AURA_EXPORT DragDropDelegate* GetDragDropDelegate(Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_DRAG_DROP_DELEGATE_H_ diff --git a/ui/wm/public/scoped_tooltip_disabler.cc b/ui/wm/public/scoped_tooltip_disabler.cc new file mode 100644 index 0000000..45a39ca --- /dev/null +++ b/ui/wm/public/scoped_tooltip_disabler.cc @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/scoped_tooltip_disabler.h" + +#include "ui/aura/window.h" +#include "ui/wm/public/tooltip_client.h" + +namespace aura { +namespace client { + +ScopedTooltipDisabler::ScopedTooltipDisabler(aura::Window* window) + : root_(window ? window->GetRootWindow() : NULL) { + if (root_) { + root_->AddObserver(this); + TooltipClient* client = GetTooltipClient(root_); + if (client) + client->SetTooltipsEnabled(false); + } +} + +ScopedTooltipDisabler::~ScopedTooltipDisabler() { + EnableTooltips(); +} + +void ScopedTooltipDisabler::EnableTooltips() { + if (!root_) + return; + TooltipClient* client = GetTooltipClient(root_); + if (client) + client->SetTooltipsEnabled(true); + root_->RemoveObserver(this); + root_ = NULL; +} + +void ScopedTooltipDisabler::OnWindowDestroying(aura::Window* window) { + EnableTooltips(); +} + + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/scoped_tooltip_disabler.h b/ui/wm/public/scoped_tooltip_disabler.h new file mode 100644 index 0000000..0fd3e11 --- /dev/null +++ b/ui/wm/public/scoped_tooltip_disabler.h @@ -0,0 +1,39 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_SCOPED_TOOLTIP_DISABLER_H_ +#define UI_WM_PUBLIC_SCOPED_TOOLTIP_DISABLER_H_ + +#include "ui/aura/window_observer.h" + +namespace aura { +namespace client { + +// Use to temporarily disable tooltips. +class AURA_EXPORT ScopedTooltipDisabler : aura::WindowObserver { + public: + // Disables tooltips on |window| (does nothing if |window| is NULL). Tooltips + // are reenabled from the destructor when there are no most outstanding + // ScopedTooltipDisablers for |window|. + explicit ScopedTooltipDisabler(aura::Window* window); + virtual ~ScopedTooltipDisabler(); + + private: + // Reenables the tooltips on the TooltipClient. + void EnableTooltips(); + + // aura::WindowObserver: + virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; + + // The RootWindow to disable Tooltips on; NULL if the Window passed to the + // constructor was not in a root or the root has been destroyed. + aura::Window* root_; + + DISALLOW_COPY_AND_ASSIGN(ScopedTooltipDisabler); +}; + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_SCOPED_TOOLTIP_DISABLER_H_ diff --git a/ui/wm/public/tooltip_client.cc b/ui/wm/public/tooltip_client.cc new file mode 100644 index 0000000..b473238 --- /dev/null +++ b/ui/wm/public/tooltip_client.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/tooltip_client.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::TooltipClient*) +DECLARE_WINDOW_PROPERTY_TYPE(base::string16*) + +namespace aura { +namespace client { + +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + TooltipClient*, kRootWindowTooltipClientKey, NULL); +DEFINE_LOCAL_WINDOW_PROPERTY_KEY(base::string16*, kTooltipTextKey, NULL); + +void SetTooltipClient(Window* root_window, TooltipClient* client) { + DCHECK_EQ(root_window->GetRootWindow(), root_window); + root_window->SetProperty(kRootWindowTooltipClientKey, client); +} + +TooltipClient* GetTooltipClient(Window* root_window) { + if (root_window) + DCHECK_EQ(root_window->GetRootWindow(), root_window); + return root_window ? + root_window->GetProperty(kRootWindowTooltipClientKey) : NULL; +} + +void SetTooltipText(Window* window, base::string16* tooltip_text) { + window->SetProperty(kTooltipTextKey, tooltip_text); +} + +const base::string16 GetTooltipText(Window* window) { + base::string16* string_ptr = window->GetProperty(kTooltipTextKey); + return string_ptr ? *string_ptr : base::string16(); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/tooltip_client.h b/ui/wm/public/tooltip_client.h new file mode 100644 index 0000000..f592b21 --- /dev/null +++ b/ui/wm/public/tooltip_client.h @@ -0,0 +1,45 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_TOOLTIP_CLIENT_H_ +#define UI_WM_PUBLIC_TOOLTIP_CLIENT_H_ + +#include "ui/aura/aura_export.h" +#include "ui/gfx/font.h" + +namespace aura { +class Window; +namespace client { + +class ScopedTooltipDisabler; + +class AURA_EXPORT TooltipClient { + public: + // Informs the shell tooltip manager of change in tooltip for window |target|. + virtual void UpdateTooltip(Window* target) = 0; + + // Sets the time after which the tooltip is hidden for Window |target|. If + // |timeout_in_ms| is <= 0, the tooltip is shown indefinitely. + virtual void SetTooltipShownTimeout(Window* target, int timeout_in_ms) = 0; + + protected: + // Enables/Disables tooltips. This is treated as a reference count. Consumers + // must use ScopedTooltipDisabler to enable/disabled tooltips. + virtual void SetTooltipsEnabled(bool enable) = 0; + + private: + friend class ScopedTooltipDisabler; +}; + +AURA_EXPORT void SetTooltipClient(Window* root_window, + TooltipClient* client); +AURA_EXPORT TooltipClient* GetTooltipClient(Window* root_window); + +AURA_EXPORT void SetTooltipText(Window* window, base::string16* tooltip_text); +AURA_EXPORT const base::string16 GetTooltipText(Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_TOOLTIP_CLIENT_H_ diff --git a/ui/wm/public/transient_window_client.cc b/ui/wm/public/transient_window_client.cc new file mode 100644 index 0000000..aab8e51 --- /dev/null +++ b/ui/wm/public/transient_window_client.cc @@ -0,0 +1,25 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/transient_window_client.h" + +namespace aura { +namespace client { + +namespace { + +TransientWindowClient* instance = NULL; + +} // namespace + +void SetTransientWindowClient(TransientWindowClient* client) { + instance = client; +} + +TransientWindowClient* GetTransientWindowClient() { + return instance; +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/transient_window_client.h b/ui/wm/public/transient_window_client.h new file mode 100644 index 0000000..2086100 --- /dev/null +++ b/ui/wm/public/transient_window_client.h @@ -0,0 +1,47 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_TRANSIENT_WINDOW_CLIENT_H_ +#define UI_WM_PUBLIC_TRANSIENT_WINDOW_CLIENT_H_ + +#include "base/basictypes.h" +#include "ui/aura/aura_export.h" + +namespace aura { + +class Window; + +namespace client { + +// TransientWindowClient is used to add or remove transient windows. Transient +// children get the following behavior: +// . The transient parent destroys any transient children when it is +// destroyed. This means a transient child is destroyed if either its parent +// or transient parent is destroyed. +// . If a transient child and its transient parent share the same parent, then +// transient children are always ordered above the transient parent. +// Transient windows are typically used for popups and menus. +// TODO(sky): nuke this class and replace with calls to TransientWindowManager. +// This is temporary until we start moving to ui/wm. +class AURA_EXPORT TransientWindowClient { + public: + virtual void AddTransientChild(Window* parent, Window* child) = 0; + virtual void RemoveTransientChild(Window* parent, Window* child) = 0; + virtual Window* GetTransientParent(Window* window) = 0; + virtual const Window* GetTransientParent(const Window* window) = 0; + + protected: + virtual ~TransientWindowClient() {} +}; + +// Sets/gets the TransientWindowClient. This does *not* take ownership of +// |client|. It is assumed the caller will invoke SetTransientWindowClient(NULL) +// before deleting |client|. +AURA_EXPORT void SetTransientWindowClient(TransientWindowClient* client); +AURA_EXPORT TransientWindowClient* GetTransientWindowClient(); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_TRANSIENT_WINDOW_CLIENT_H_ diff --git a/ui/wm/public/window_move_client.cc b/ui/wm/public/window_move_client.cc new file mode 100644 index 0000000..44ccca9 --- /dev/null +++ b/ui/wm/public/window_move_client.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/wm/public/window_move_client.h" + +#include "ui/aura/window.h" +#include "ui/aura/window_property.h" + +DECLARE_WINDOW_PROPERTY_TYPE(aura::client::WindowMoveClient*) + +namespace aura { +namespace client { + +// A property key to store a client that handles window moves. +DEFINE_LOCAL_WINDOW_PROPERTY_KEY( + WindowMoveClient*, kWindowMoveClientKey, NULL); + +void SetWindowMoveClient(Window* window, WindowMoveClient* client) { + window->SetProperty(kWindowMoveClientKey, client); +} + +WindowMoveClient* GetWindowMoveClient(Window* window) { + return window->GetProperty(kWindowMoveClientKey); +} + +} // namespace client +} // namespace aura diff --git a/ui/wm/public/window_move_client.h b/ui/wm/public/window_move_client.h new file mode 100644 index 0000000..b8943d3 --- /dev/null +++ b/ui/wm/public/window_move_client.h @@ -0,0 +1,56 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_WM_PUBLIC_WINDOW_MOVE_CLIENT_H_ +#define UI_WM_PUBLIC_WINDOW_MOVE_CLIENT_H_ + +#include "ui/aura/aura_export.h" +#include "ui/gfx/vector2d.h" + +namespace gfx { +class Point; +} + +namespace aura { +class Window; +namespace client { + +enum WindowMoveResult { + MOVE_SUCCESSFUL, // Moving window was successful. + MOVE_CANCELED // Moving window was canceled. +}; + +enum WindowMoveSource { + WINDOW_MOVE_SOURCE_MOUSE, + WINDOW_MOVE_SOURCE_TOUCH, +}; + +// An interface implemented by an object that manages programatically keyed +// window moving. +class AURA_EXPORT WindowMoveClient { + public: + // Starts a nested message loop for moving the window. |drag_offset| is the + // offset from the window origin to the cursor when the drag was started. + // Returns MOVE_SUCCESSFUL if the move has completed successfully, or + // MOVE_CANCELED otherwise. + virtual WindowMoveResult RunMoveLoop(Window* window, + const gfx::Vector2d& drag_offset, + WindowMoveSource source) = 0; + + // Ends a previously started move loop. + virtual void EndMoveLoop() = 0; + + protected: + virtual ~WindowMoveClient() {} +}; + +// Sets/Gets the activation client for the specified window. +AURA_EXPORT void SetWindowMoveClient(Window* window, + WindowMoveClient* client); +AURA_EXPORT WindowMoveClient* GetWindowMoveClient(Window* window); + +} // namespace client +} // namespace aura + +#endif // UI_WM_PUBLIC_WINDOW_MOVE_CLIENT_H_ |