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" 148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ui/aura/client/focus_client.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/screen_position_client.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_move_client.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/client/window_tree_client.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_types.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.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/ui_base_types.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h" 26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.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" 31e6402284a6517cc047655bc051a7f1269e182040Ben Murdoch#include "ui/views/corewm/window_util.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/drag_utils.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/ime/input_method_bridge.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/views_delegate.h" 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/drop_helper.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 { 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::ParentWindowWithContext( 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window_, context->GetRootWindow(), 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 (params.type != Widget::InitParams::TYPE_TOOLTIP) 1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type != Widget::InitParams::TYPE_TOOLTIP && 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.type != Widget::InitParams::TYPE_POPUP) { 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetDragDropDelegate(window_, this); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetActivationDelegate(window_, this); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kCanMaximizeKey, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->widget_delegate()->CanMaximize()); 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kCanResizeKey, 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->widget_delegate()->CanResize()); 187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_.reset(new WindowReorderer(window_, 189868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetWidget()->GetRootView())); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldUseNativeFrame() const { 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There is only one frame type for aura. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FrameTypeChanged() { 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is called when the Theme has changed; forward the event to the root 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // widget. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->ThemeChanged(); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetRootView()->SchedulePaint(); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetWidget() { 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const Widget* NativeWidgetAura::GetWidget() const { 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeView NativeWidgetAura::GetNativeView() const { 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetTopLevelWidget() { 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_widget ? native_widget->GetWidget() : NULL; 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const ui::Compositor* NativeWidgetAura::GetCompositor() const { 2303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer()->GetCompositor() : NULL; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::Compositor* NativeWidgetAura::GetCompositor() { 2343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer()->GetCompositor() : NULL; 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)ui::Layer* NativeWidgetAura::GetLayer() { 2383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->layer() : NULL; 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void NativeWidgetAura::ReorderNativeViews() { 242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_->ReorderChildWindows(); 243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ViewRemoved(View* view) { 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->ResetTargetViewIfEquals(view); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetNativeWindowProperty(name, value); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_ ? window_->GetNativeWindowProperty(name) : NULL; 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TooltipManager* NativeWidgetAura::GetTooltipManager() const { 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return tooltip_manager_.get(); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCapture() { 2643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 2653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetCapture(); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ReleaseCapture() { 2693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 2703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->ReleaseCapture(); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasCapture() const { 2743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->HasCapture(); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)InputMethod* NativeWidgetAura::CreateInputMethod() { 2783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 2793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return NULL; 2801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window = window_->GetRootWindow(); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::InputMethod* host = 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) root_window->GetProperty(aura::client::kRootWindowInputMethodKey); 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return new InputMethodBridge(this, host, true); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return this; 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 2913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 2923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 2933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When centering window, we take the intersection of the host and 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the parent. We assume the root window represents the visible 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // rect of a single screen. 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(window_).work_area(); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(window_->GetRootWindow()); 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = work_area.origin(); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &origin); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) work_area.set_origin(origin); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.Intersect(work_area); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |window_|'s transient parent's bounds are big enough to fit it, then we 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // center it with respect to the transient parent. 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->transient_parent()) { 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect transient_parent_rect = window_->transient_parent()-> 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetBoundsInRootWindow(); 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.Intersect(work_area); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (transient_parent_rect.height() >= size.height() && 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.width() >= size.width()) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds = transient_parent_rect; 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds( 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.width(), 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.height()); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't size the window bigger than the parent, otherwise the user may not be 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // able to close or move it. 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.AdjustToFit(parent_bounds); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Convert the bounds back relative to the parent. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = window_bounds.origin(); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window::ConvertPointToTarget(window_->GetRootWindow(), 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent(), &origin); 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.set_origin(origin); 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(window_bounds); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetWindowPlacement( 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* bounds, 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WindowShowState* show_state) const { 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The interface specifies returning restored bounds, not current bounds. 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *bounds = GetRestoredBounds(); 3453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey) : 3463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ui::SHOW_STATE_DEFAULT; 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool NativeWidgetAura::SetWindowTitle(const string16& title) { 350a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!window_) 351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return false; 352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (window_->title() == title) 353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return false; 354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) window_->set_title(title); 355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return true; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::ImageSkia& app_icon) { 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Aura doesn't have window icons. 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (modal_type != ui::MODAL_TYPE_NONE) 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, modal_type); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { 3693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // View-to-screen coordinate system transformations depend on this returning 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the full window bounds, for example View::ConvertPointToScreen(). 3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetRestoredBounds() const { 3793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 3803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Rect(); 3813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restored bounds should only be relevant if the window is minimized or 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maximized. However, in some places the code expects GetRestoredBounds() 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to return the current window bounds if the window is not in either state. 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMinimized() || IsMaximized() || IsFullscreen()) { 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restore bounds are in screen coordinates, no need to convert. 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* restore_bounds = 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->GetProperty(aura::client::kRestoreBoundsKey); 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (restore_bounds) 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return *restore_bounds; 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetBoundsInScreen(); 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { 3963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 3973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 3983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root = window_->GetRootWindow(); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root) { 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(root); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Display dst_display = 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->SetBounds(window_, bounds, dst_display); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(bounds); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetSize(const gfx::Size& size) { 4143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { 4193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 4203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent() == native_view->parent()) 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildAbove(window_, native_view); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAtTop() { 4253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent()->StackChildAtTop(window_); 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { 4303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 4313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->parent() == native_view->parent()) 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildBelow(window_, native_view); 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetShape(gfx::NativeRegion region) { 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // No need for this. Just delete and ignore. 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete region; 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Close() { 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |window_| may already be deleted by parent window. This can happen 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when this widget is child widget or has transient parent 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and ownership is WIDGET_OWNS_NATIVE_WIDGET. 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_ || 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) { 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SuppressPaint(); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Hide(); 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!close_widget_factory_.HasWeakPtrs()) { 453c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoop::current()->PostTask( 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&NativeWidgetAura::CloseNow, 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) close_widget_factory_.GetWeakPtr())); 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CloseNow() { 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete window_; 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Show() { 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowWithWindowState(ui::SHOW_STATE_INACTIVE); 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Hide() { 4693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 4703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->Hide(); 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowMaximizedWithBounds( 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& restored_bounds) { 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetRestoreBounds(window_, restored_bounds); 476ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 4803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 4813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 4823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN) 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, state); 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Show(); 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (can_activate_) { 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state != ui::SHOW_STATE_INACTIVE) 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Activate(); 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFocus() should be always be called, even for 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SHOW_STATE_INACTIVE. When a frameless modal dialog is created by 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a widget of TYPE_WINDOW_FRAMELESS, Widget::Show() will call into 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this function with the window state SHOW_STATE_INACTIVE, 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFoucs() has to be called so that the dialog can get focus. 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This also matches NativeWidgetWin which invokes SetInitialFocus 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // regardless of show state. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetInitialFocus(); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsVisible() const { 5013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->IsVisible(); 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Activate() { 5053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 5063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 5073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't necessarily have a root window yet. This can happen with 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // constrained windows. 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetRootWindow()) { 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetProperty(aura::client::kDrawAttentionKey)) 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, false); 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Deactivate() { 5193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 5203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsActive() const { 526e6402284a6517cc047655bc051a7f1269e182040Ben Murdoch return window_ && corewm::IsActiveWindow(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) 5344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool NativeWidgetAura::IsAlwaysOnTop() const { 5354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return window_ && window_->GetProperty(aura::client::kAlwaysOnTopKey); 5364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 5374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Maximize() { 5393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Minimize() { 5443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMaximized() const { 5493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MAXIMIZED; 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMinimized() const { 5543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MINIMIZED; 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Restore() { 5593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetFullscreen(bool fullscreen) { 5643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_ || IsFullscreen() == fullscreen) 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; // Nothing to do. 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Save window state before entering full screen so that it could restored 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when exiting full screen. 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (fullscreen) 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty( 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::kShowStateKey, 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsFullscreen() const { 5783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return window_ && window_->GetProperty(aura::client::kShowStateKey) == 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_FULLSCREEN; 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetOpacity(unsigned char opacity) { 5833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->layer()->SetOpacity(opacity / 255.0); 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FlashFrame(bool flash) { 5923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 5933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, flash); 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::RunShellDrag(View* view, 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ui::OSExchangeData& data, 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location, 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int operation, 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::DragDropTypes::DragEventSource source) { 6013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 6023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) views::RunShellDrag(window_, data, location, operation, source); 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SchedulePaintInRect(rect); 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_ = cursor; 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::CursorClient* cursor_client = 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (cursor_client) 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_client->SetCursor(cursor); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool NativeWidgetAura::IsMouseEventsEnabled() const { 6193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 6203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return false; 6217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::CursorClient* cursor_client = 6227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 6237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; 6247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 6257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ClearNativeFocus() { 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ && client && window_->Contains(client->GetFocusedWindow())) 6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client->ResetFocusWithinActiveWindow(window_); 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { 6333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!window_) 6343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Rect(); 6353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return gfx::Screen::GetScreenFor(window_)-> 6363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GetDisplayNearestWindow(window_).work_area(); 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2d& drag_offset, 64168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Widget::MoveLoopSource source, 64268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Widget::MoveLoopEscapeBehavior escape_behavior) { 64368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // |escape_behavior| is only needed on windows when running the native message 64468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // loop. 6453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetCapture(); 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WindowMoveSource window_move_source = 6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) source == Widget::MOVE_LOOP_SOURCE_MOUSE ? 6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_MOUSE : 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_TOUCH; 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura::client::GetWindowMoveClient(window_->parent())->RunMoveLoop( 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_, drag_offset, window_move_source) == 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::MOVE_SUCCESSFUL) { 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_SUCCESSFUL; 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_CANCELED; 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::EndMoveLoop() { 6623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_ && window_->parent() && 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())->EndMoveLoop(); 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { 6693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (window_) 6703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 675558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return DesktopRootWindowHost::GetNativeTheme(window_); 676558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#else 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ui::NativeThemeAura::instance(); 678558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 68158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void NativeWidgetAura::OnRootViewLayout() const { 68258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 68358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, views::InputMethodDelegate implementation: 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FocusManager* focus_manager = GetWidget()->GetFocusManager(); 6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (key.handled() || !focus_manager) 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) focus_manager->OnKeyEvent(key); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDelegate implementation: 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Size NativeWidgetAura::GetMinimumSize() const { 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetMinimumSize(); 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size NativeWidgetAura::GetMaximumSize() const { 7032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return delegate_->GetMaximumSize(); 7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& new_bounds) { 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.origin() != new_bounds.origin()) 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetMove(); 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.size() != new_bounds.size()) 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cursor_; 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetNonClientComponent(point); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* child, 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location) { 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (widget_delegate && 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't descend into |child| if there is a view with a Layer that contains 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the point and is stacked above |child|s layer. 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<ui::Layer*> Layers; 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Layers& root_layers(delegate_->GetRootLayers()); 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layers.empty()) 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator child_layer_iter( 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), child->layer())); 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (child_layer_iter == window_->layer()->children().end()) 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (std::vector<ui::Layer*>::const_reverse_iterator i = root_layers.rbegin(); 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != root_layers.rend(); ++i) { 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::Layer* layer = *i; 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (layer->visible() && layer->bounds().Contains(location)) { 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator root_layer_iter( 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), layer)); 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layer_iter > child_layer_iter) 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::CanFocus() { 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_; 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnCaptureLost() { 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnMouseCaptureLost(); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetPaint(canvas); 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Repainting with new scale factor will paint the content at the right scale. 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroying() { 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroying(); 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the aura::Window is destroyed, we can no longer show tooltips. 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_.reset(); 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroyed() { 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_ = NULL; 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroyed(); 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete this; 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetVisibilityChanged(visible); 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasHitTestMask() const { 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->HasHitTestMask(); 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(mask); 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->GetHitTestMask(mask); 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 80058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void NativeWidgetAura::DidRecreateLayer(ui::Layer *old_layer, 80158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ui::Layer *new_layer) { 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, ui::EventHandler implementation: 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 8083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (event->is_char()) { 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a ui::InputMethod object is attached to the root window, character 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // events are handled inside the object and are not passed to this function. 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If such object is not attached, character events might be sent (e.g. on 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Windows). In this case, we just skip these. 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Renderer may send a key event back to us if the key event wasn't handled, 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the window may be invisible by that time. 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!window_->IsVisible()) 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetInputMethod()->DispatchKeyEvent(*event); 8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event->SetHandled(); 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 8253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 8272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->type() == ui::ET_MOUSEWHEEL) { 8282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->handled()) 8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (tooltip_manager_.get()) 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_->UpdateTooltip(); 8351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget()); 8362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnScrollEvent(event); 8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { 8443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 845f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DCHECK(window_->IsVisible() || event->IsEndingEvent()); 8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnTouchEvent(event); 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { 8503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DCHECK(window_); 851f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DCHECK(window_->IsVisible() || event->IsEndingEvent()); 8522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnGestureEvent(event); 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationDelegate implementation: 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NativeWidgetAura::ShouldActivate() const { 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_ && delegate_->CanActivate(); 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationChangeObserver implementation: 8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowActivated(aura::Window* gained_active, 8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_active) { 8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(window_ == gained_active || window_ == lost_active); 8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetFocusManager()) { 8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_active) 8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->RestoreFocusedView(); 8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else if (window_ == lost_active) 8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->StoreFocusedView(true); 8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsVisible() && GetWidget()->non_client_view()) 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->non_client_view()->SchedulePaint(); 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::FocusChangeObserver: 8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_focus) { 8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_focus) { 8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In aura, it is possible for child native widgets to take input and focus, 8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this differs from the behavior on windows. 8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) // Null in tests. 8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnFocus(); 8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeFocus(lost_focus); 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (window_ == lost_focus) { 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // GetInputMethod() recreates the input method if it's previously been 8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destroyed. If we get called during destruction, the input method will be 8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // gone, and creating a new one and telling it that we lost the focus will 8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // trigger a DCHECK (the new input method doesn't think that we have the 8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // focus and doesn't expect a blur). OnBlur() shouldn't be called during 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // case in tests). 8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!destroying_) { 8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnBlur(); 9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (client) // NULL during destruction of aura::Window. 9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeBlur(client->GetFocusedWindow()); 9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDragDropDelegate implementation: 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return last_drop_operation_; 9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragExited() { 9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->OnDragExit(); 9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return drop_helper_->OnDrop(event.data(), event.location(), 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_); 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// NativeWidgetAura, NativeWidget implementation: 9407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ui::EventHandler* NativeWidgetAura::GetEventHandler() { 9427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return this; 9437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 9447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 9457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, protected: 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetAura::~NativeWidgetAura() { 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) destroying_ = true; 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete delegate_; 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CloseNow(); 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, private: 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetInitialFocus() { 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The window does not get keyboard messages unless we focus it. 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!GetWidget()->SetInitialFocus()) 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Focus(); 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Widget, public: 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::NotifyLocaleChanged() { 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deliberately not implemented. 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 974f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) || (defined(USE_X11) && !defined(OS_CHROMEOS)) 975558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochvoid CloseWindow(aura::Window* window) { 976558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (window) { 977558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Widget* widget = Widget::GetWidgetForNativeView(window); 9782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (widget && widget->is_secondary_widget()) 979c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // To avoid the delay in shutdown caused by using Close which may wait 980c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // for animations, use CloseNow. Because this is only used on secondary 981c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // widgets it seems relatively safe to skip the extra processing of 982c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Close. 983c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) widget->CloseNow(); 9842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 985558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} 986f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 987f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 988558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) 989558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochBOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { 990558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch aura::Window* root_window = 991558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostWin::GetContentWindowForHWND(hwnd); 992558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CloseWindow(root_window); 9932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return TRUE; 9942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 996558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} // namespace 9972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::CloseAllSecondaryWidgets() { 10002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 10012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 1003558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 10043240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_X11) && !defined(OS_CHROMEOS) 1005558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::vector<aura::Window*> open_windows = 1006558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::GetAllOpenWindows(); 1007558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::for_each(open_windows.begin(), open_windows.end(), CloseWindow); 1008558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::CleanUpWindowList(); 1009558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Widget::ConvertRect(const Widget* source, 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Widget* target, 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* rect) { 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal { 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// internal::NativeWidgetPrivate, public: 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) internal::NativeWidgetDelegate* delegate) { 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new NativeWidgetAura(delegate); 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 10323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Cast must match type supplied to RegisterNativeWidgetForWindow(). 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data()); 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeWindow native_window) { 10393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Cast must match type supplied to RegisterNativeWidgetForWindow(). 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data()); 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window = native_view; 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* top_level_native_widget = NULL; 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (window) { 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); 10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget) 10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) top_level_native_widget = native_widget; 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window = window->parent(); 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return top_level_native_widget; 10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets* children) { 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Code expects widget for |native_view| to be added to |children|. 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetNativeWidgetForNativeView(native_view)); 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget && native_widget->GetWidget()) 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) children->insert(native_widget->GetWidget()); 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const aura::Window::Windows& child_windows = native_view->children(); 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (aura::Window::Windows::const_iterator i = child_windows.begin(); 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != child_windows.end(); ++i) { 10713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GetAllChildWidgets((*i), children); 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// static 1076d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, 1077d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Widget::Widgets* owned) { 1078d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const aura::Window::Windows& transient_children = 1079d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) native_view->transient_children(); 1080d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) for (aura::Window::Windows::const_iterator i = transient_children.begin(); 1081d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) i != transient_children.end(); ++i) { 1082d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( 1083d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) GetNativeWidgetForNativeView(*i)); 1084d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) if (native_widget && native_widget->GetWidget()) 1085d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) owned->insert(native_widget->GetWidget()); 1086d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) GetAllOwnedWidgets((*i), owned); 1087d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 1088d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 1089d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, 10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView new_parent) { 10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(native_view != new_parent); 10945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView previous_parent = native_view->parent(); 10965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (previous_parent == new_parent) 10975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets widgets; 11005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetAllChildWidgets(native_view, &widgets); 11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First notify all the widgets that they are being disassociated 11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from their previous parent. 11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 1106424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyWillChange(); 11075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 11085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (new_parent) { 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new_parent->AddChild(native_view); 11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The following looks weird, but it's the equivalent of what aura has 11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always done. (The previous behaviour of aura::Window::SetParent() used 11141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NULL as a special value that meant ask the WindowTreeClient where things 11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // should go.) 11162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This probably isn't strictly correct, but its an invariant that a Window 11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in use will be attached to a RootWindow, so we can't just call 11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // RemoveChild here. The only possible thing that could assign a RootWindow 11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in this case is the stacking client of the current RootWindow. This 11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // matches our previous behaviour; the global stacking client would almost 11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always reattach the window to the same RootWindow. 11231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window = native_view->GetRootWindow(); 11241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::ParentWindowWithContext( 11251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) native_view, root_window, root_window->GetBoundsInScreen()); 11262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // And now, notify them that they have a brand new parent. 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 11305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 1131424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyChanged(); 11325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 11335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 11365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsMouseButtonDown() { 11374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return aura::Env::GetInstance()->IsMouseButtonDown(); 11385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 11415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsTouchDown() { 11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::Env::GetInstance()->is_touch_down(); 11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace internal 11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 1147