native_widget_aura.cc revision 3551c9c881056c480085172ff9840cab31610854
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)#include "ui/views/widget/native_widget_aura.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 85e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string_util.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/activation_client.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/cursor_client.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/drag_drop_client.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/screen_position_client.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/stacking_client.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_move_client.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_types.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/focus_manager.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_observer.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/dragdrop/os_exchange_data.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/events/event.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_base_types.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/canvas.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/font.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/native_theme/native_theme_aura.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/drag_utils.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/ime/input_method_bridge.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/views_delegate.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/drop_helper.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_aura_window_observer.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_delegate.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/root_view.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/tooltip_manager_aura.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_aura_utils.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h" 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/widget/window_reorderer.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/scoped_gdi_object.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/win_util.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util_win.h" 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h" 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 513240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_X11) && !defined(OS_CHROMEOS) 52558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" 53558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 54558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_root_window_host.h" 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, public: 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : delegate_(delegate), 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_(new aura::Window(this)), 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) close_widget_factory_(this), 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) can_activate_(true), 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) destroying_(false), 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_(gfx::kNullCursor), 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) saved_window_state_(ui::SHOW_STATE_DEFAULT) { 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::SetFocusChangeObserver(window_, this); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::SetActivationChangeObserver(window_, this); 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Font NativeWidgetAura::GetWindowTitleFont() { 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NONCLIENTMETRICS ncm; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::GetNonClientMetrics(&ncm); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Font(caption_font); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Font(); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// static 993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void NativeWidgetAura::RegisterNativeWidgetForWindow( 1003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) internal::NativeWidgetPrivate* native_widget, 1013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::Window* window) { 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window->set_user_data(native_widget); 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 1043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, internal::NativeWidgetPrivate implementation: 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Aura needs to know which desktop (Ash or regular) will manage this widget. 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See Widget::InitParams::context for details. 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(params.parent || params.context); 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_ = params.ownership; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) RegisterNativeWidgetForWindow(this, window_); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, params.show_state); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type == Widget::InitParams::TYPE_BUBBLE) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetHideOnDeactivate(window_, true); 120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch window_->SetTransparent( 121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Init(params.layer_type); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type == Widget::InitParams::TYPE_CONTROL) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Show(); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) delegate_->OnNativeWidgetCreated(false); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds = params.bounds; 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView parent = params.parent; 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView context = params.context; 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!params.child) { 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set up the transient child before the window is added. This way the 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // LayoutManager knows the window has a transient parent. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent->AddTransientChild(window_); 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!context) 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) context = parent; 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent = NULL; 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetAlwaysOnTop before SetParent so that always-on-top container is used. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAlwaysOnTop(params.keep_on_top); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure we have a real |window_bounds|. 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (parent && window_bounds == gfx::Rect()) { 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a parent is specified but no bounds are given, 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // use the origin of the parent's display so that the widget 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be added to the same display as the parent. 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(parent).bounds(); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.set_origin(bounds.origin()); 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (parent) { 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) parent->AddChild(window_); 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetDefaultParentByRootWindow(context->GetRootWindow(), 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_bounds); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Wait to set the bounds until we have a parent. That way we can know our 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true state/bounds (the LayoutManager may enforce a particular 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // state/bounds). 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMaximized()) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetRestoreBounds(window_, window_bounds); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetBounds(window_bounds); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->set_ignore_events(!params.accept_events); 168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) can_activate_ = params.can_activate && 169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) params.type != Widget::InitParams::TYPE_CONTROL && 170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) params.type != Widget::InitParams::TYPE_TOOLTIP; 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(GetWidget()->GetRootView()); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_MACOSX) 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type != Widget::InitParams::TYPE_TOOLTIP) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget())); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // !defined(OS_MACOSX) 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type != Widget::InitParams::TYPE_TOOLTIP && 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.type != Widget::InitParams::TYPE_POPUP) { 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetDragDropDelegate(window_, this); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetActivationDelegate(window_, this); 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kCanMaximizeKey, 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->widget_delegate()->CanMaximize()); 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kCanResizeKey, 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->widget_delegate()->CanResize()); 189868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 190868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_.reset(new WindowReorderer(window_, 191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetWidget()->GetRootView())); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldUseNativeFrame() const { 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There is only one frame type for aura. 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FrameTypeChanged() { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is called when the Theme has changed; forward the event to the root 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // widget. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->ThemeChanged(); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetRootView()->SchedulePaint(); 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetWidget() { 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const Widget* NativeWidgetAura::GetWidget() const { 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeView NativeWidgetAura::GetNativeView() const { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetTopLevelWidget() { 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_widget ? native_widget->GetWidget() : NULL; 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const ui::Compositor* NativeWidgetAura::GetCompositor() const { 2323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer()->GetCompositor() : NULL; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::Compositor* NativeWidgetAura::GetCompositor() { 2363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer()->GetCompositor() : NULL; 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)ui::Layer* NativeWidgetAura::GetLayer() { 2403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer() : NULL; 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void NativeWidgetAura::ReorderNativeViews() { 244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_->ReorderChildWindows(); 245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ViewRemoved(View* view) { 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->ResetTargetViewIfEquals(view); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetNativeWindowProperty(name, value); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_ ? window_->GetNativeWindowProperty(name) : NULL; 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TooltipManager* NativeWidgetAura::GetTooltipManager() const { 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return tooltip_manager_.get(); 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCapture() { 2663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetCapture(); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ReleaseCapture() { 2713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 2723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->ReleaseCapture(); 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasCapture() const { 2763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->HasCapture(); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)InputMethod* NativeWidgetAura::CreateInputMethod() { 2803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 2813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return NULL; 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::RootWindow* root_window = window_->GetRootWindow(); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::InputMethod* host = 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) root_window->GetProperty(aura::client::kRootWindowInputMethodKey); 2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return new InputMethodBridge(this, host, true); 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return this; 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 2933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 2943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 2953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When centering window, we take the intersection of the host and 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the parent. We assume the root window represents the visible 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // rect of a single screen. 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(window_).work_area(); 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(window_->GetRootWindow()); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = work_area.origin(); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &origin); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) work_area.set_origin(origin); 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.Intersect(work_area); 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |window_|'s transient parent's bounds are big enough to fit it, then we 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // center it with respect to the transient parent. 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->transient_parent()) { 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect transient_parent_rect = window_->transient_parent()-> 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetBoundsInRootWindow(); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.Intersect(work_area); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (transient_parent_rect.height() >= size.height() && 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.width() >= size.width()) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds = transient_parent_rect; 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds( 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.width(), 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.height()); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't size the window bigger than the parent, otherwise the user may not be 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // able to close or move it. 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.AdjustToFit(parent_bounds); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Convert the bounds back relative to the parent. 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = window_bounds.origin(); 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window::ConvertPointToTarget(window_->GetRootWindow(), 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent(), &origin); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.set_origin(origin); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(window_bounds); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetWindowPlacement( 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* bounds, 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WindowShowState* show_state) const { 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The interface specifies returning restored bounds, not current bounds. 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *bounds = GetRestoredBounds(); 3473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey) : 3483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ui::SHOW_STATE_DEFAULT; 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetWindowTitle(const string16& title) { 3523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 3533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->set_title(title); 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::ImageSkia& app_icon) { 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Aura doesn't have window icons. 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (modal_type != ui::MODAL_TYPE_NONE) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, modal_type); 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { 3673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // View-to-screen coordinate system transformations depend on this returning 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the full window bounds, for example View::ConvertPointToScreen(). 3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetRestoredBounds() const { 3773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 3783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Rect(); 3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restored bounds should only be relevant if the window is minimized or 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maximized. However, in some places the code expects GetRestoredBounds() 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to return the current window bounds if the window is not in either state. 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMinimized() || IsMaximized() || IsFullscreen()) { 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restore bounds are in screen coordinates, no need to convert. 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* restore_bounds = 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->GetProperty(aura::client::kRestoreBoundsKey); 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (restore_bounds) 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return *restore_bounds; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetBoundsInScreen(); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { 3943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 3953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 3963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::RootWindow* root = window_->GetRootWindow(); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root) { 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(root); 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Display dst_display = 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->SetBounds(window_, bounds, dst_display); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(bounds); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetSize(const gfx::Size& size) { 4123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { 4173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 4183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent() == native_view->parent()) 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildAbove(window_, native_view); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAtTop() { 4233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent()->StackChildAtTop(window_); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { 4283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 4293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent() == native_view->parent()) 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildBelow(window_, native_view); 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetShape(gfx::NativeRegion region) { 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // No need for this. Just delete and ignore. 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete region; 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Close() { 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |window_| may already be deleted by parent window. This can happen 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when this widget is child widget or has transient parent 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and ownership is WIDGET_OWNS_NATIVE_WIDGET. 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_ || 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) { 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SuppressPaint(); 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Hide(); 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!close_widget_factory_.HasWeakPtrs()) { 451c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoop::current()->PostTask( 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&NativeWidgetAura::CloseNow, 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) close_widget_factory_.GetWeakPtr())); 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CloseNow() { 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete window_; 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Show() { 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowWithWindowState(ui::SHOW_STATE_INACTIVE); 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Hide() { 4673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->Hide(); 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowMaximizedWithBounds( 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& restored_bounds) { 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetRestoreBounds(window_, restored_bounds); 474ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 4783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 4793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 4803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN) 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, state); 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Show(); 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (can_activate_) { 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state != ui::SHOW_STATE_INACTIVE) 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Activate(); 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFocus() should be always be called, even for 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SHOW_STATE_INACTIVE. When a frameless modal dialog is created by 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a widget of TYPE_WINDOW_FRAMELESS, Widget::Show() will call into 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this function with the window state SHOW_STATE_INACTIVE, 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFoucs() has to be called so that the dialog can get focus. 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This also matches NativeWidgetWin which invokes SetInitialFocus 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // regardless of show state. 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetInitialFocus(); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsVisible() const { 4993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->IsVisible(); 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Activate() { 5033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 5043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 5053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't necessarily have a root window yet. This can happen with 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // constrained windows. 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetRootWindow()) { 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetProperty(aura::client::kDrawAttentionKey)) 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, false); 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Deactivate() { 5173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 5183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsActive() const { 5243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && 5253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())-> 5263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GetActiveWindow() == window_; 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { 5303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top); 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Maximize() { 5353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Minimize() { 5403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMaximized() const { 5453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MAXIMIZED; 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMinimized() const { 5503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MINIMIZED; 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Restore() { 5553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetFullscreen(bool fullscreen) { 5603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_ || IsFullscreen() == fullscreen) 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; // Nothing to do. 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Save window state before entering full screen so that it could restored 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when exiting full screen. 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (fullscreen) 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty( 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::kShowStateKey, 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsFullscreen() const { 5743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_FULLSCREEN; 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetOpacity(unsigned char opacity) { 5793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->layer()->SetOpacity(opacity / 255.0); 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FlashFrame(bool flash) { 5883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, flash); 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::RunShellDrag(View* view, 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ui::OSExchangeData& data, 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location, 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int operation, 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::DragDropTypes::DragEventSource source) { 5973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) views::RunShellDrag(window_, data, location, operation, source); 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SchedulePaintInRect(rect); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_ = cursor; 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::CursorClient* cursor_client = 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (cursor_client) 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_client->SetCursor(cursor); 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool NativeWidgetAura::IsMouseEventsEnabled() const { 6153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 6163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return false; 6177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::CursorClient* cursor_client = 6187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 6197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; 6207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ClearNativeFocus() { 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ && client && window_->Contains(client->GetFocusedWindow())) 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client->ResetFocusWithinActiveWindow(window_); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { 6293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 6303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Rect(); 6313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Screen::GetScreenFor(window_)-> 6323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GetDisplayNearestWindow(window_).work_area(); 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { 6363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 6373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 6383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!value) { 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) active_window_observer_.reset(); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) active_window_observer_.reset( 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new NativeWidgetAuraWindowObserver(window_, delegate_)); 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2d& drag_offset, 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Widget::MoveLoopSource source) { 6503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetCapture(); 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WindowMoveSource window_move_source = 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) source == Widget::MOVE_LOOP_SOURCE_MOUSE ? 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_MOUSE : 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_TOUCH; 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura::client::GetWindowMoveClient(window_->parent())->RunMoveLoop( 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_, drag_offset, window_move_source) == 6592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::MOVE_SUCCESSFUL) { 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_SUCCESSFUL; 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_CANCELED; 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::EndMoveLoop() { 6673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())->EndMoveLoop(); 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { 6743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 6753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 680558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return DesktopRootWindowHost::GetNativeTheme(window_); 681558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#else 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ui::NativeThemeAura::instance(); 683558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, views::InputMethodDelegate implementation: 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FocusManager* focus_manager = GetWidget()->GetFocusManager(); 6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (key.handled() || !focus_manager) 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) focus_manager->OnKeyEvent(key); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDelegate implementation: 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Size NativeWidgetAura::GetMinimumSize() const { 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetMinimumSize(); 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size NativeWidgetAura::GetMaximumSize() const { 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return delegate_->GetMaximumSize(); 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& new_bounds) { 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.origin() != new_bounds.origin()) 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetMove(); 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.size() != new_bounds.size()) 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cursor_; 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetNonClientComponent(point); 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* child, 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location) { 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (widget_delegate && 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't descend into |child| if there is a view with a Layer that contains 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the point and is stacked above |child|s layer. 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<ui::Layer*> Layers; 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Layers& root_layers(delegate_->GetRootLayers()); 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layers.empty()) 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator child_layer_iter( 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), child->layer())); 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (child_layer_iter == window_->layer()->children().end()) 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (std::vector<ui::Layer*>::const_reverse_iterator i = root_layers.rbegin(); 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != root_layers.rend(); ++i) { 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::Layer* layer = *i; 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (layer->visible() && layer->bounds().Contains(location)) { 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator root_layer_iter( 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), layer)); 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layer_iter > child_layer_iter) 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::CanFocus() { 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_; 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnCaptureLost() { 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnMouseCaptureLost(); 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetPaint(canvas); 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Repainting with new scale factor will paint the content at the right scale. 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroying() { 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroying(); 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the aura::Window is destroyed, we can no longer show tooltips. 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_.reset(); 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroyed() { 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_ = NULL; 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroyed(); 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete this; 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetVisibilityChanged(visible); 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasHitTestMask() const { 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->HasHitTestMask(); 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(mask); 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->GetHitTestMask(mask); 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ui::Texture> NativeWidgetAura::CopyTexture() { 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The layer we create doesn't have an external texture, so this should never 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // get invoked. 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return scoped_refptr<ui::Texture>(); 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, ui::EventHandler implementation: 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 8133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (event->is_char()) { 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a ui::InputMethod object is attached to the root window, character 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // events are handled inside the object and are not passed to this function. 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If such object is not attached, character events might be sent (e.g. on 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Windows). In this case, we just skip these. 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Renderer may send a key event back to us if the key event wasn't handled, 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the window may be invisible by that time. 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!window_->IsVisible()) 8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetInputMethod()->DispatchKeyEvent(*event); 8262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event->SetHandled(); 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 8303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->type() == ui::ET_MOUSEWHEEL) { 8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 8342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->handled()) 8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (tooltip_manager_.get()) 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_->UpdateTooltip(); 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnScrollEvent(event); 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { 8483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnTouchEvent(event); 8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { 8543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnGestureEvent(event); 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationDelegate implementation: 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NativeWidgetAura::ShouldActivate() const { 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_ && delegate_->CanActivate(); 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationChangeObserver implementation: 8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowActivated(aura::Window* gained_active, 8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_active) { 8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(window_ == gained_active || window_ == lost_active); 8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetFocusManager()) { 8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_active) 8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->RestoreFocusedView(); 8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else if (window_ == lost_active) 8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->StoreFocusedView(true); 8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsVisible() && GetWidget()->non_client_view()) 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->non_client_view()->SchedulePaint(); 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::FocusChangeObserver: 8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_focus) { 8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_focus) { 8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In aura, it is possible for child native widgets to take input and focus, 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this differs from the behavior on windows. 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) // Null in tests. 8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnFocus(); 8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeFocus(lost_focus); 8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (window_ == lost_focus) { 8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // GetInputMethod() recreates the input method if it's previously been 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destroyed. If we get called during destruction, the input method will be 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // gone, and creating a new one and telling it that we lost the focus will 8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // trigger a DCHECK (the new input method doesn't think that we have the 8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // focus and doesn't expect a blur). OnBlur() shouldn't be called during 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the 9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // case in tests). 9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!destroying_) { 9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) 9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnBlur(); 9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (client) // NULL during destruction of aura::Window. 9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeBlur(client->GetFocusedWindow()); 9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDragDropDelegate implementation: 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return last_drop_operation_; 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragExited() { 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->OnDragExit(); 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return drop_helper_->OnDrop(event.data(), event.location(), 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_); 9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// NativeWidgetAura, NativeWidget implementation: 9447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ui::EventHandler* NativeWidgetAura::GetEventHandler() { 9467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return this; 9477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 9487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, protected: 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetAura::~NativeWidgetAura() { 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) destroying_ = true; 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete delegate_; 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CloseNow(); 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, private: 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetInitialFocus() { 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The window does not get keyboard messages unless we focus it. 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!GetWidget()->SetInitialFocus()) 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Focus(); 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Widget, public: 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::NotifyLocaleChanged() { 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deliberately not implemented. 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 978558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochvoid CloseWindow(aura::Window* window) { 979558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (window) { 980558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Widget* widget = Widget::GetWidgetForNativeView(window); 9812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (widget && widget->is_secondary_widget()) 982c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // To avoid the delay in shutdown caused by using Close which may wait 983c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // for animations, use CloseNow. Because this is only used on secondary 984c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // widgets it seems relatively safe to skip the extra processing of 985c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Close. 986c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) widget->CloseNow(); 9872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 988558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} 989558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) 990558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochBOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { 991558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch aura::Window* root_window = 992558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostWin::GetContentWindowForHWND(hwnd); 993558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CloseWindow(root_window); 9942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return TRUE; 9952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 997558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} // namespace 9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::CloseAllSecondaryWidgets() { 10012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); 10032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1004558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 10053240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_X11) && !defined(OS_CHROMEOS) 1006558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::vector<aura::Window*> open_windows = 1007558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::GetAllOpenWindows(); 1008558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::for_each(open_windows.begin(), open_windows.end(), CloseWindow); 1009558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::CleanUpWindowList(); 1010558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Widget::ConvertRect(const Widget* source, 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Widget* target, 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* rect) { 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal { 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// internal::NativeWidgetPrivate, public: 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) internal::NativeWidgetDelegate* delegate) { 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new NativeWidgetAura(delegate); 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 10333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Cast must match type supplied to RegisterNativeWidgetForWindow(). 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data()); 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeWindow native_window) { 10403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Cast must match type supplied to RegisterNativeWidgetForWindow(). 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data()); 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window = native_view; 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* top_level_native_widget = NULL; 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (window) { 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget) 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) top_level_native_widget = native_widget; 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window = window->parent(); 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return top_level_native_widget; 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets* children) { 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Code expects widget for |native_view| to be added to |children|. 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetNativeWidgetForNativeView(native_view)); 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget && native_widget->GetWidget()) 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) children->insert(native_widget->GetWidget()); 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const aura::Window::Windows& child_windows = native_view->children(); 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (aura::Window::Windows::const_iterator i = child_windows.begin(); 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != child_windows.end(); ++i) { 10723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GetAllChildWidgets((*i), children); 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, 10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView new_parent) { 10795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(native_view != new_parent); 10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView previous_parent = native_view->parent(); 10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (previous_parent == new_parent) 10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets widgets; 10865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetAllChildWidgets(native_view, &widgets); 10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First notify all the widgets that they are being disassociated 10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from their previous parent. 10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); 10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (new_parent) { 10962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new_parent->AddChild(native_view); 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 10982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The following looks weird, but it's the equivalent of what aura has 10992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always done. (The previous behaviour of aura::Window::SetParent() used 11002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // NULL as a special value that meant ask the StackingClient where things 11012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // should go.) 11022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 11032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This probably isn't strictly correct, but its an invariant that a Window 11042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in use will be attached to a RootWindow, so we can't just call 11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // RemoveChild here. The only possible thing that could assign a RootWindow 11062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in this case is the stacking client of the current RootWindow. This 11072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // matches our previous behaviour; the global stacking client would almost 11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always reattach the window to the same RootWindow. 11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::RootWindow* root_window = native_view->GetRootWindow(); 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) native_view->SetDefaultParentByRootWindow( 11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) root_window, root_window->GetBoundsInScreen()); 11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // And now, notify them that they have a brand new parent. 11155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 11165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 11175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); 11185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 11195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsMouseButtonDown() { 11235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::Env::GetInstance()->is_mouse_button_down(); 11245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsTouchDown() { 11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::Env::GetInstance()->is_touch_down(); 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace internal 11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 1133