This source file includes following definitions.
- CreateParentWindow
- OnWindowDestroying
- OnWindowBoundsChanged
- child_window_
- GetDefaultParent
- OnKeyEvent
- OnWindowDestroyed
- widget_type_
- ForWindow
- OnHostClosed
- OnDesktopWindowTreeHostDestroyed
- HandleActivationChanged
- InitNativeWidget
- CreateNonClientFrameView
- ShouldUseNativeFrame
- ShouldWindowContentsBeTransparent
- FrameTypeChanged
- GetWidget
- GetWidget
- GetNativeView
- GetNativeWindow
- GetTopLevelWidget
- GetCompositor
- GetCompositor
- GetLayer
- ReorderNativeViews
- ViewRemoved
- SetNativeWindowProperty
- GetNativeWindowProperty
- GetTooltipManager
- SetCapture
- ReleaseCapture
- HasCapture
- CreateInputMethod
- GetInputMethodDelegate
- CenterWindow
- GetWindowPlacement
- SetWindowTitle
- SetWindowIcons
- InitModalType
- GetWindowBoundsInScreen
- GetClientAreaBoundsInScreen
- GetRestoredBounds
- SetBounds
- SetSize
- StackAbove
- StackAtTop
- StackBelow
- SetShape
- Close
- CloseNow
- Show
- Hide
- ShowMaximizedWithBounds
- ShowWithWindowState
- IsVisible
- Activate
- Deactivate
- IsActive
- SetAlwaysOnTop
- IsAlwaysOnTop
- SetVisibleOnAllWorkspaces
- Maximize
- Minimize
- IsMaximized
- IsMinimized
- Restore
- SetFullscreen
- IsFullscreen
- SetOpacity
- SetUseDragFrame
- FlashFrame
- RunShellDrag
- SchedulePaintInRect
- SetCursor
- IsMouseEventsEnabled
- ClearNativeFocus
- GetWorkAreaBoundsInScreen
- RunMoveLoop
- EndMoveLoop
- SetVisibilityChangedAnimationsEnabled
- GetNativeTheme
- OnRootViewLayout
- GetMinimumSize
- GetMaximumSize
- GetCursor
- GetNonClientComponent
- ShouldDescendIntoChildForEventHandling
- CanFocus
- OnCaptureLost
- OnPaint
- OnDeviceScaleFactorChanged
- OnWindowDestroying
- OnWindowDestroyed
- OnWindowTargetVisibilityChanged
- HasHitTestMask
- GetHitTestMask
- OnKeyEvent
- OnMouseEvent
- OnScrollEvent
- OnGestureEvent
- ShouldActivate
- OnWindowActivated
- OnWindowFocused
- DispatchKeyEventPostIME
- OnDragEntered
- OnDragUpdated
- OnDragExited
- OnPerformDrop
- OnHostCloseRequested
- OnHostResized
- OnHostMoved
- GetEventHandler
- InstallInputMethodEventFilter
- UpdateWindowTransparency
- RootWindowDestroyed
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_property.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/display.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size_conversions.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/drag_utils.h"
#include "ui/views/ime/input_method.h"
#include "ui/views/ime/input_method_bridge.h"
#include "ui/views/view_constants_aura.h"
#include "ui/views/widget/desktop_aura/desktop_capture_client.h"
#include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
#include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
#include "ui/views/widget/desktop_aura/desktop_event_client.h"
#include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
#include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
#include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/tooltip_manager_aura.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_aura_utils.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/widget/window_reorderer.h"
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/cursor_manager.h"
#include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/input_method_event_filter.h"
#include "ui/wm/core/native_cursor_manager.h"
#include "ui/wm/core/shadow_controller.h"
#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/visibility_controller.h"
#include "ui/wm/core/window_modality_controller.h"
#include "ui/wm/public/activation_client.h"
#include "ui/wm/public/drag_drop_client.h"
#if defined(OS_WIN)
#include "ui/base/win/shell.h"
#include "ui/gfx/win/dpi.h"
#endif
DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(VIEWS_EXPORT,
views::DesktopNativeWidgetAura*);
namespace views {
DEFINE_WINDOW_PROPERTY_KEY(DesktopNativeWidgetAura*,
kDesktopNativeWidgetAuraKey, NULL);
namespace {
class DesktopNativeWidgetTopLevelHandler : public aura::WindowObserver {
public:
static aura::Window* CreateParentWindow(aura::Window* child_window,
const gfx::Rect& bounds,
bool full_screen,
bool root_is_always_on_top) {
DesktopNativeWidgetTopLevelHandler* top_level_handler =
new DesktopNativeWidgetTopLevelHandler;
child_window->SetBounds(gfx::Rect(bounds.size()));
Widget::InitParams init_params;
init_params.type = full_screen ? Widget::InitParams::TYPE_WINDOW :
Widget::InitParams::TYPE_POPUP;
init_params.bounds = bounds;
init_params.ownership = Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
init_params.layer_type = aura::WINDOW_LAYER_NOT_DRAWN;
init_params.can_activate = full_screen;
init_params.keep_on_top = root_is_always_on_top;
top_level_handler->top_level_widget_ = new Widget();
top_level_handler->top_level_widget_->Init(init_params);
top_level_handler->top_level_widget_->SetFullscreen(full_screen);
top_level_handler->top_level_widget_->Show();
aura::Window* native_window =
top_level_handler->top_level_widget_->GetNativeView();
child_window->AddObserver(top_level_handler);
native_window->AddObserver(top_level_handler);
top_level_handler->child_window_ = child_window;
return native_window;
}
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
window->RemoveObserver(this);
if (top_level_widget_ &&
window == top_level_widget_->GetNativeView()) {
top_level_widget_ = NULL;
return;
}
if (top_level_widget_) {
DCHECK(top_level_widget_->GetNativeView());
top_level_widget_->GetNativeView()->RemoveObserver(this);
top_level_widget_->Close();
top_level_widget_ = NULL;
}
delete this;
}
virtual void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE {
if (top_level_widget_ && window == child_window_)
top_level_widget_->SetSize(new_bounds.size());
}
private:
DesktopNativeWidgetTopLevelHandler()
: top_level_widget_(NULL),
child_window_(NULL) {}
virtual ~DesktopNativeWidgetTopLevelHandler() {}
Widget* top_level_widget_;
aura::Window* child_window_;
DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetTopLevelHandler);
};
class DesktopNativeWidgetAuraWindowTreeClient :
public aura::client::WindowTreeClient {
public:
explicit DesktopNativeWidgetAuraWindowTreeClient(
aura::Window* root_window)
: root_window_(root_window) {
aura::client::SetWindowTreeClient(root_window_, this);
}
virtual ~DesktopNativeWidgetAuraWindowTreeClient() {
aura::client::SetWindowTreeClient(root_window_, NULL);
}
virtual aura::Window* GetDefaultParent(aura::Window* context,
aura::Window* window,
const gfx::Rect& bounds) OVERRIDE {
bool is_fullscreen = window->GetProperty(aura::client::kShowStateKey) ==
ui::SHOW_STATE_FULLSCREEN;
bool is_menu = window->type() == ui::wm::WINDOW_TYPE_MENU;
if (is_fullscreen || is_menu) {
bool root_is_always_on_top = false;
internal::NativeWidgetPrivate* native_widget =
DesktopNativeWidgetAura::ForWindow(root_window_);
if (native_widget)
root_is_always_on_top = native_widget->IsAlwaysOnTop();
return DesktopNativeWidgetTopLevelHandler::CreateParentWindow(
window, bounds, is_fullscreen, root_is_always_on_top);
}
return root_window_;
}
private:
aura::Window* root_window_;
DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAuraWindowTreeClient);
};
}
class FocusManagerEventHandler : public ui::EventHandler {
public:
FocusManagerEventHandler(DesktopNativeWidgetAura* desktop_native_widget_aura)
: desktop_native_widget_aura_(desktop_native_widget_aura) {}
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
Widget* widget = desktop_native_widget_aura_->GetWidget();
if (widget && widget->GetFocusManager()->GetFocusedView() &&
!widget->GetFocusManager()->OnKeyEvent(*event)) {
event->SetHandled();
}
}
private:
DesktopNativeWidgetAura* desktop_native_widget_aura_;
DISALLOW_COPY_AND_ASSIGN(FocusManagerEventHandler);
};
class RootWindowDestructionObserver : public aura::WindowObserver {
public:
explicit RootWindowDestructionObserver(DesktopNativeWidgetAura* parent)
: parent_(parent) {}
virtual ~RootWindowDestructionObserver() {}
private:
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
parent_->RootWindowDestroyed();
window->RemoveObserver(this);
delete this;
}
DesktopNativeWidgetAura* parent_;
DISALLOW_COPY_AND_ASSIGN(RootWindowDestructionObserver);
};
int DesktopNativeWidgetAura::cursor_reference_count_ = 0;
DesktopNativeCursorManager* DesktopNativeWidgetAura::native_cursor_manager_ =
NULL;
wm::CursorManager* DesktopNativeWidgetAura::cursor_manager_ = NULL;
DesktopNativeWidgetAura::DesktopNativeWidgetAura(
internal::NativeWidgetDelegate* delegate)
: desktop_window_tree_host_(NULL),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
close_widget_factory_(this),
can_activate_(true),
content_window_container_(NULL),
content_window_(new aura::Window(this)),
native_widget_delegate_(delegate),
last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
restore_focus_on_activate_(false),
cursor_(gfx::kNullCursor),
widget_type_(Widget::InitParams::TYPE_WINDOW) {
aura::client::SetFocusChangeObserver(content_window_, this);
aura::client::SetActivationChangeObserver(content_window_, this);
}
DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
delete native_widget_delegate_;
else
CloseNow();
}
DesktopNativeWidgetAura* DesktopNativeWidgetAura::ForWindow(
aura::Window* window) {
return window->GetProperty(kDesktopNativeWidgetAuraKey);
}
void DesktopNativeWidgetAura::OnHostClosed() {
if (window_modality_controller_)
window_modality_controller_.reset();
{
aura::Window* capture_window = capture_client_->GetCaptureWindow();
if (capture_window && host_->window()->Contains(capture_window))
capture_window->ReleaseCapture();
}
shadow_controller_.reset();
tooltip_manager_.reset();
host_->window()->RemovePreTargetHandler(tooltip_controller_.get());
aura::client::SetTooltipClient(host_->window(), NULL);
tooltip_controller_.reset();
root_window_event_filter_->RemoveHandler(input_method_event_filter_.get());
window_tree_client_.reset();
capture_client_.reset();
host_->window()->RemovePreTargetHandler(focus_client_.get());
aura::client::SetFocusClient(host_->window(), NULL);
aura::client::SetActivationClient(host_->window(), NULL);
focus_client_.reset();
host_->RemoveObserver(this);
host_.reset();
desktop_window_tree_host_ = NULL;
content_window_ = NULL;
native_widget_delegate_->OnNativeWidgetDestroyed();
if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
delete this;
}
void DesktopNativeWidgetAura::OnDesktopWindowTreeHostDestroyed(
aura::WindowTreeHost* host) {
aura::client::SetDispatcherClient(host->window(), NULL);
dispatcher_client_.reset();
native_cursor_manager_->RemoveHost(host);
aura::client::SetScreenPositionClient(host->window(), NULL);
position_client_.reset();
aura::client::SetDragDropClient(host->window(), NULL);
drag_drop_client_.reset();
aura::client::SetEventClient(host->window(), NULL);
event_client_.reset();
}
void DesktopNativeWidgetAura::HandleActivationChanged(bool active) {
native_widget_delegate_->OnNativeWidgetActivationChanged(active);
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(host_->window());
if (!activation_client)
return;
if (active) {
if (GetWidget()->HasFocusManager()) {
View* view_for_activation =
GetWidget()->GetFocusManager()->GetFocusedView() ?
GetWidget()->GetFocusManager()->GetFocusedView() :
GetWidget()->GetFocusManager()->GetStoredFocusView();
if (!view_for_activation)
view_for_activation = GetWidget()->GetRootView();
activation_client->ActivateWindow(
view_for_activation->GetWidget()->GetNativeView());
}
} else {
aura::Window* active_window = activation_client->GetActiveWindow();
if (active_window)
activation_client->DeactivateWindow(active_window);
}
}
void DesktopNativeWidgetAura::InitNativeWidget(
const Widget::InitParams& params) {
ownership_ = params.ownership;
widget_type_ = params.type;
NativeWidgetAura::RegisterNativeWidgetForWindow(this, content_window_);
if (params.type == Widget::InitParams::TYPE_WINDOW &&
!params.remove_standard_frame) {
content_window_->SetProperty(aura::client::kAnimationsDisabledKey, true);
}
content_window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
content_window_->Init(params.layer_type);
wm::SetShadowType(content_window_, wm::SHADOW_TYPE_NONE);
content_window_container_ = new aura::Window(NULL);
content_window_container_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
content_window_container_->Show();
content_window_container_->AddChild(content_window_);
desktop_window_tree_host_ = params.desktop_window_tree_host ?
params.desktop_window_tree_host :
DesktopWindowTreeHost::Create(native_widget_delegate_, this);
host_.reset(desktop_window_tree_host_->AsWindowTreeHost());
desktop_window_tree_host_->Init(content_window_, params);
host_->window()->SetProperty(views::kDesktopRootWindow, true);
host_->InitHost();
host_->window()->AddChild(content_window_container_);
host_->window()->SetProperty(kDesktopNativeWidgetAuraKey, this);
host_->window()->AddObserver(new RootWindowDestructionObserver(this));
if (widget_type_ == Widget::InitParams::TYPE_WINDOW)
window_modality_controller_.reset(
new wm::WindowModalityController(host_->window()));
root_window_event_filter_ = new wm::CompoundEventFilter;
host_->window()->SetEventFilter(root_window_event_filter_);
cursor_reference_count_++;
if (!native_cursor_manager_) {
native_cursor_manager_ = new DesktopNativeCursorManager(
DesktopCursorLoaderUpdater::Create());
}
if (!cursor_manager_) {
cursor_manager_ = new wm::CursorManager(
scoped_ptr<wm::NativeCursorManager>(native_cursor_manager_));
}
native_cursor_manager_->AddHost(host());
aura::client::SetCursorClient(host_->window(), cursor_manager_);
desktop_window_tree_host_->OnNativeWidgetCreated(params);
UpdateWindowTransparency();
capture_client_.reset(new DesktopCaptureClient(host_->window()));
wm::FocusController* focus_controller =
new wm::FocusController(new DesktopFocusRules(content_window_));
focus_client_.reset(focus_controller);
aura::client::SetFocusClient(host_->window(), focus_controller);
aura::client::SetActivationClient(host_->window(), focus_controller);
host_->window()->AddPreTargetHandler(focus_controller);
dispatcher_client_.reset(new DesktopDispatcherClient);
aura::client::SetDispatcherClient(host_->window(),
dispatcher_client_.get());
position_client_.reset(new DesktopScreenPositionClient(host_->window()));
InstallInputMethodEventFilter();
drag_drop_client_ = desktop_window_tree_host_->CreateDragDropClient(
native_cursor_manager_);
aura::client::SetDragDropClient(host_->window(),
drag_drop_client_.get());
static_cast<aura::client::FocusClient*>(focus_client_.get())->
FocusWindow(content_window_);
OnHostResized(host());
host_->AddObserver(this);
window_tree_client_.reset(
new DesktopNativeWidgetAuraWindowTreeClient(host_->window()));
drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
aura::client::SetDragDropDelegate(content_window_, this);
tooltip_manager_.reset(new TooltipManagerAura(GetWidget()));
tooltip_controller_.reset(
new corewm::TooltipController(
desktop_window_tree_host_->CreateTooltip()));
aura::client::SetTooltipClient(host_->window(),
tooltip_controller_.get());
host_->window()->AddPreTargetHandler(tooltip_controller_.get());
if (params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW) {
visibility_controller_.reset(new wm::VisibilityController);
aura::client::SetVisibilityClient(host_->window(),
visibility_controller_.get());
wm::SetChildWindowVisibilityChangesAnimated(host_->window());
wm::SetChildWindowVisibilityChangesAnimated(
content_window_container_);
}
if (params.type == Widget::InitParams::TYPE_WINDOW) {
focus_manager_event_handler_.reset(new FocusManagerEventHandler(this));
host_->window()->AddPreTargetHandler(focus_manager_event_handler_.get());
}
event_client_.reset(new DesktopEventClient);
aura::client::SetEventClient(host_->window(), event_client_.get());
aura::client::GetFocusClient(content_window_)->FocusWindow(content_window_);
aura::client::SetActivationDelegate(content_window_, this);
shadow_controller_.reset(new wm::ShadowController(
aura::client::GetActivationClient(host_->window())));
content_window_->SetProperty(aura::client::kCanMaximizeKey,
GetWidget()->widget_delegate()->CanMaximize());
content_window_->SetProperty(aura::client::kCanResizeKey,
GetWidget()->widget_delegate()->CanResize());
window_reorderer_.reset(new WindowReorderer(content_window_,
GetWidget()->GetRootView()));
}
NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() {
return desktop_window_tree_host_->CreateNonClientFrameView();
}
bool DesktopNativeWidgetAura::ShouldUseNativeFrame() const {
return desktop_window_tree_host_->ShouldUseNativeFrame();
}
bool DesktopNativeWidgetAura::ShouldWindowContentsBeTransparent() const {
return desktop_window_tree_host_->ShouldWindowContentsBeTransparent();
}
void DesktopNativeWidgetAura::FrameTypeChanged() {
desktop_window_tree_host_->FrameTypeChanged();
UpdateWindowTransparency();
}
Widget* DesktopNativeWidgetAura::GetWidget() {
return native_widget_delegate_->AsWidget();
}
const Widget* DesktopNativeWidgetAura::GetWidget() const {
return native_widget_delegate_->AsWidget();
}
gfx::NativeView DesktopNativeWidgetAura::GetNativeView() const {
return content_window_;
}
gfx::NativeWindow DesktopNativeWidgetAura::GetNativeWindow() const {
return content_window_;
}
Widget* DesktopNativeWidgetAura::GetTopLevelWidget() {
return GetWidget();
}
const ui::Compositor* DesktopNativeWidgetAura::GetCompositor() const {
return content_window_ ? content_window_->layer()->GetCompositor() : NULL;
}
ui::Compositor* DesktopNativeWidgetAura::GetCompositor() {
return const_cast<ui::Compositor*>(
const_cast<const DesktopNativeWidgetAura*>(this)->GetCompositor());
}
ui::Layer* DesktopNativeWidgetAura::GetLayer() {
return content_window_ ? content_window_->layer() : NULL;
}
void DesktopNativeWidgetAura::ReorderNativeViews() {
window_reorderer_->ReorderChildWindows();
}
void DesktopNativeWidgetAura::ViewRemoved(View* view) {
DCHECK(drop_helper_.get() != NULL);
drop_helper_->ResetTargetViewIfEquals(view);
}
void DesktopNativeWidgetAura::SetNativeWindowProperty(const char* name,
void* value) {
if (content_window_)
content_window_->SetNativeWindowProperty(name, value);
}
void* DesktopNativeWidgetAura::GetNativeWindowProperty(const char* name) const {
return content_window_ ?
content_window_->GetNativeWindowProperty(name) : NULL;
}
TooltipManager* DesktopNativeWidgetAura::GetTooltipManager() const {
return tooltip_manager_.get();
}
void DesktopNativeWidgetAura::SetCapture() {
if (!content_window_)
return;
content_window_->SetCapture();
}
void DesktopNativeWidgetAura::ReleaseCapture() {
if (!content_window_)
return;
content_window_->ReleaseCapture();
}
bool DesktopNativeWidgetAura::HasCapture() const {
return content_window_ && content_window_->HasCapture() &&
desktop_window_tree_host_->HasCapture();
}
InputMethod* DesktopNativeWidgetAura::CreateInputMethod() {
ui::InputMethod* host = input_method_event_filter_->input_method();
return new InputMethodBridge(this, host, false);
}
internal::InputMethodDelegate*
DesktopNativeWidgetAura::GetInputMethodDelegate() {
return this;
}
void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) {
if (content_window_)
desktop_window_tree_host_->CenterWindow(size);
}
void DesktopNativeWidgetAura::GetWindowPlacement(
gfx::Rect* bounds,
ui::WindowShowState* maximized) const {
if (content_window_)
desktop_window_tree_host_->GetWindowPlacement(bounds, maximized);
}
bool DesktopNativeWidgetAura::SetWindowTitle(const base::string16& title) {
if (!content_window_)
return false;
return desktop_window_tree_host_->SetWindowTitle(title);
}
void DesktopNativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
if (content_window_)
desktop_window_tree_host_->SetWindowIcons(window_icon, app_icon);
}
void DesktopNativeWidgetAura::InitModalType(ui::ModalType modal_type) {
desktop_window_tree_host_->InitModalType(modal_type);
}
gfx::Rect DesktopNativeWidgetAura::GetWindowBoundsInScreen() const {
return content_window_ ?
desktop_window_tree_host_->GetWindowBoundsInScreen() : gfx::Rect();
}
gfx::Rect DesktopNativeWidgetAura::GetClientAreaBoundsInScreen() const {
return content_window_ ?
desktop_window_tree_host_->GetClientAreaBoundsInScreen() : gfx::Rect();
}
gfx::Rect DesktopNativeWidgetAura::GetRestoredBounds() const {
return content_window_ ?
desktop_window_tree_host_->GetRestoredBounds() : gfx::Rect();
}
void DesktopNativeWidgetAura::SetBounds(const gfx::Rect& bounds) {
if (!content_window_)
return;
float scale = 1;
aura::Window* root = host_->window();
if (root) {
scale = gfx::Screen::GetScreenFor(root)->
GetDisplayNearestWindow(root).device_scale_factor();
}
gfx::Rect bounds_in_pixels(
gfx::ToCeiledPoint(gfx::ScalePoint(bounds.origin(), scale)),
gfx::ToFlooredSize(gfx::ScaleSize(bounds.size(), scale)));
desktop_window_tree_host_->AsWindowTreeHost()->SetBounds(bounds_in_pixels);
}
void DesktopNativeWidgetAura::SetSize(const gfx::Size& size) {
if (content_window_)
desktop_window_tree_host_->SetSize(size);
}
void DesktopNativeWidgetAura::StackAbove(gfx::NativeView native_view) {
}
void DesktopNativeWidgetAura::StackAtTop() {
if (content_window_)
desktop_window_tree_host_->StackAtTop();
}
void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) {
}
void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) {
if (content_window_)
desktop_window_tree_host_->SetShape(shape);
}
void DesktopNativeWidgetAura::Close() {
if (!content_window_)
return;
content_window_->SuppressPaint();
content_window_->Hide();
desktop_window_tree_host_->Close();
}
void DesktopNativeWidgetAura::CloseNow() {
if (content_window_)
desktop_window_tree_host_->CloseNow();
}
void DesktopNativeWidgetAura::Show() {
if (!content_window_)
return;
desktop_window_tree_host_->AsWindowTreeHost()->Show();
content_window_->Show();
}
void DesktopNativeWidgetAura::Hide() {
if (!content_window_)
return;
desktop_window_tree_host_->AsWindowTreeHost()->Hide();
content_window_->Hide();
}
void DesktopNativeWidgetAura::ShowMaximizedWithBounds(
const gfx::Rect& restored_bounds) {
if (!content_window_)
return;
desktop_window_tree_host_->ShowMaximizedWithBounds(restored_bounds);
content_window_->Show();
}
void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
if (!content_window_)
return;
desktop_window_tree_host_->ShowWindowWithState(state);
content_window_->Show();
}
bool DesktopNativeWidgetAura::IsVisible() const {
return content_window_ && desktop_window_tree_host_->IsVisible();
}
void DesktopNativeWidgetAura::Activate() {
if (content_window_)
desktop_window_tree_host_->Activate();
}
void DesktopNativeWidgetAura::Deactivate() {
if (content_window_)
desktop_window_tree_host_->Deactivate();
}
bool DesktopNativeWidgetAura::IsActive() const {
return content_window_ && desktop_window_tree_host_->IsActive();
}
void DesktopNativeWidgetAura::SetAlwaysOnTop(bool always_on_top) {
if (content_window_)
desktop_window_tree_host_->SetAlwaysOnTop(always_on_top);
}
bool DesktopNativeWidgetAura::IsAlwaysOnTop() const {
return content_window_ && desktop_window_tree_host_->IsAlwaysOnTop();
}
void DesktopNativeWidgetAura::SetVisibleOnAllWorkspaces(bool always_visible) {
if (content_window_)
desktop_window_tree_host_->SetVisibleOnAllWorkspaces(always_visible);
}
void DesktopNativeWidgetAura::Maximize() {
if (content_window_)
desktop_window_tree_host_->Maximize();
}
void DesktopNativeWidgetAura::Minimize() {
if (content_window_)
desktop_window_tree_host_->Minimize();
}
bool DesktopNativeWidgetAura::IsMaximized() const {
return content_window_ && desktop_window_tree_host_->IsMaximized();
}
bool DesktopNativeWidgetAura::IsMinimized() const {
return content_window_ && desktop_window_tree_host_->IsMinimized();
}
void DesktopNativeWidgetAura::Restore() {
if (content_window_)
desktop_window_tree_host_->Restore();
}
void DesktopNativeWidgetAura::SetFullscreen(bool fullscreen) {
if (content_window_)
desktop_window_tree_host_->SetFullscreen(fullscreen);
}
bool DesktopNativeWidgetAura::IsFullscreen() const {
return content_window_ && desktop_window_tree_host_->IsFullscreen();
}
void DesktopNativeWidgetAura::SetOpacity(unsigned char opacity) {
if (content_window_)
desktop_window_tree_host_->SetOpacity(opacity);
}
void DesktopNativeWidgetAura::SetUseDragFrame(bool use_drag_frame) {
}
void DesktopNativeWidgetAura::FlashFrame(bool flash_frame) {
if (content_window_)
desktop_window_tree_host_->FlashFrame(flash_frame);
}
void DesktopNativeWidgetAura::RunShellDrag(
View* view,
const ui::OSExchangeData& data,
const gfx::Point& location,
int operation,
ui::DragDropTypes::DragEventSource source) {
views::RunShellDrag(content_window_, data, location, operation, source);
}
void DesktopNativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
if (content_window_)
content_window_->SchedulePaintInRect(rect);
}
void DesktopNativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
cursor_ = cursor;
aura::client::CursorClient* cursor_client =
aura::client::GetCursorClient(host_->window());
if (cursor_client)
cursor_client->SetCursor(cursor);
}
bool DesktopNativeWidgetAura::IsMouseEventsEnabled() const {
if (!content_window_)
return false;
aura::client::CursorClient* cursor_client =
aura::client::GetCursorClient(host_->window());
return cursor_client ? cursor_client->IsMouseEventsEnabled() : true;
}
void DesktopNativeWidgetAura::ClearNativeFocus() {
desktop_window_tree_host_->ClearNativeFocus();
if (ShouldActivate()) {
aura::client::GetFocusClient(content_window_)->
ResetFocusWithinActiveWindow(content_window_);
}
}
gfx::Rect DesktopNativeWidgetAura::GetWorkAreaBoundsInScreen() const {
return desktop_window_tree_host_ ?
desktop_window_tree_host_->GetWorkAreaBoundsInScreen() : gfx::Rect();
}
Widget::MoveLoopResult DesktopNativeWidgetAura::RunMoveLoop(
const gfx::Vector2d& drag_offset,
Widget::MoveLoopSource source,
Widget::MoveLoopEscapeBehavior escape_behavior) {
if (!content_window_)
return Widget::MOVE_LOOP_CANCELED;
return desktop_window_tree_host_->RunMoveLoop(drag_offset, source,
escape_behavior);
}
void DesktopNativeWidgetAura::EndMoveLoop() {
if (content_window_)
desktop_window_tree_host_->EndMoveLoop();
}
void DesktopNativeWidgetAura::SetVisibilityChangedAnimationsEnabled(
bool value) {
if (content_window_)
desktop_window_tree_host_->SetVisibilityChangedAnimationsEnabled(value);
}
ui::NativeTheme* DesktopNativeWidgetAura::GetNativeTheme() const {
return DesktopWindowTreeHost::GetNativeTheme(content_window_);
}
void DesktopNativeWidgetAura::OnRootViewLayout() const {
if (content_window_)
desktop_window_tree_host_->OnRootViewLayout();
}
gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const {
return native_widget_delegate_->GetMinimumSize();
}
gfx::Size DesktopNativeWidgetAura::GetMaximumSize() const {
return native_widget_delegate_->GetMaximumSize();
}
gfx::NativeCursor DesktopNativeWidgetAura::GetCursor(const gfx::Point& point) {
return cursor_;
}
int DesktopNativeWidgetAura::GetNonClientComponent(
const gfx::Point& point) const {
return native_widget_delegate_->GetNonClientComponent(point);
}
bool DesktopNativeWidgetAura::ShouldDescendIntoChildForEventHandling(
aura::Window* child,
const gfx::Point& location) {
views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate();
return !widget_delegate ||
widget_delegate->ShouldDescendIntoChildForEventHandling(child, location);
}
bool DesktopNativeWidgetAura::CanFocus() {
return true;
}
void DesktopNativeWidgetAura::OnCaptureLost() {
native_widget_delegate_->OnMouseCaptureLost();
}
void DesktopNativeWidgetAura::OnPaint(gfx::Canvas* canvas) {
native_widget_delegate_->OnNativeWidgetPaint(canvas);
}
void DesktopNativeWidgetAura::OnDeviceScaleFactorChanged(
float device_scale_factor) {
}
void DesktopNativeWidgetAura::OnWindowDestroying(aura::Window* window) {
}
void DesktopNativeWidgetAura::OnWindowDestroyed(aura::Window* window) {
}
void DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) {
}
bool DesktopNativeWidgetAura::HasHitTestMask() const {
return native_widget_delegate_->HasHitTestMask();
}
void DesktopNativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
native_widget_delegate_->GetHitTestMask(mask);
}
void DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
if (event->is_char()) {
return;
}
if (!content_window_->IsVisible())
return;
native_widget_delegate_->OnKeyEvent(event);
if (event->handled())
return;
if (GetWidget()->HasFocusManager() &&
!GetWidget()->GetFocusManager()->OnKeyEvent(*event))
event->SetHandled();
}
void DesktopNativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
DCHECK(content_window_->IsVisible());
if (tooltip_manager_.get())
tooltip_manager_->UpdateTooltip();
TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget());
native_widget_delegate_->OnMouseEvent(event);
}
void DesktopNativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) {
if (event->type() == ui::ET_SCROLL) {
native_widget_delegate_->OnScrollEvent(event);
if (event->handled())
return;
ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event));
native_widget_delegate_->OnMouseEvent(&mwe);
if (mwe.handled())
event->SetHandled();
} else {
native_widget_delegate_->OnScrollEvent(event);
}
}
void DesktopNativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) {
native_widget_delegate_->OnGestureEvent(event);
}
bool DesktopNativeWidgetAura::ShouldActivate() const {
return can_activate_ && native_widget_delegate_->CanActivate();
}
void DesktopNativeWidgetAura::OnWindowActivated(aura::Window* gained_active,
aura::Window* lost_active) {
DCHECK(content_window_ == gained_active || content_window_ == lost_active);
if (gained_active == content_window_ && restore_focus_on_activate_) {
restore_focus_on_activate_ = false;
GetWidget()->GetFocusManager()->RestoreFocusedView();
} else if (lost_active == content_window_ && GetWidget()->HasFocusManager()) {
DCHECK(!restore_focus_on_activate_);
restore_focus_on_activate_ = true;
GetWidget()->GetFocusManager()->StoreFocusedView(false);
}
}
void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) {
if (content_window_ == gained_focus) {
desktop_window_tree_host_->OnNativeWidgetFocus();
native_widget_delegate_->OnNativeFocus(lost_focus);
InputMethod* input_method = GetWidget()->GetInputMethod();
if (input_method)
input_method->OnFocus();
} else if (content_window_ == lost_focus) {
desktop_window_tree_host_->OnNativeWidgetBlur();
native_widget_delegate_->OnNativeBlur(
aura::client::GetFocusClient(content_window_)->GetFocusedWindow());
}
}
void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
FocusManager* focus_manager =
native_widget_delegate_->AsWidget()->GetFocusManager();
native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
if (key.handled() || !focus_manager)
return;
focus_manager->OnKeyEvent(key);
}
void DesktopNativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) {
DCHECK(drop_helper_.get() != NULL);
last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
event.location(), event.source_operations());
}
int DesktopNativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) {
DCHECK(drop_helper_.get() != NULL);
last_drop_operation_ = drop_helper_->OnDragOver(event.data(),
event.location(), event.source_operations());
return last_drop_operation_;
}
void DesktopNativeWidgetAura::OnDragExited() {
DCHECK(drop_helper_.get() != NULL);
drop_helper_->OnDragExit();
}
int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
DCHECK(drop_helper_.get() != NULL);
Activate();
return drop_helper_->OnDrop(event.data(), event.location(),
last_drop_operation_);
}
void DesktopNativeWidgetAura::OnHostCloseRequested(
const aura::WindowTreeHost* host) {
GetWidget()->Close();
}
void DesktopNativeWidgetAura::OnHostResized(const aura::WindowTreeHost* host) {
if (desktop_window_tree_host_->IsAnimatingClosed())
return;
gfx::Rect new_bounds = gfx::Rect(host->window()->bounds().size());
content_window_->SetBounds(new_bounds);
if (content_window_container_)
content_window_container_->SetBounds(new_bounds);
native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
}
void DesktopNativeWidgetAura::OnHostMoved(const aura::WindowTreeHost* host,
const gfx::Point& new_origin) {
TRACE_EVENT1("views", "DesktopNativeWidgetAura::OnHostMoved",
"new_origin", new_origin.ToString());
native_widget_delegate_->OnNativeWidgetMove();
}
ui::EventHandler* DesktopNativeWidgetAura::GetEventHandler() {
return this;
}
void DesktopNativeWidgetAura::InstallInputMethodEventFilter() {
DCHECK(!input_method_event_filter_.get());
input_method_event_filter_.reset(new wm::InputMethodEventFilter(
host_->GetAcceleratedWidget()));
input_method_event_filter_->SetInputMethodPropertyInRootWindow(
host_->window());
root_window_event_filter_->AddHandler(input_method_event_filter_.get());
}
void DesktopNativeWidgetAura::UpdateWindowTransparency() {
content_window_->SetTransparent(
desktop_window_tree_host_->ShouldWindowContentsBeTransparent());
content_window_->SetFillsBoundsCompletely(true);
}
void DesktopNativeWidgetAura::RootWindowDestroyed() {
cursor_reference_count_--;
if (cursor_reference_count_ == 0) {
delete cursor_manager_;
native_cursor_manager_ = NULL;
cursor_manager_ = NULL;
}
}
}