native_widget_aura.cc revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_aura.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 85e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string_util.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/activation_client.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/cursor_client.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/drag_drop_client.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/screen_position_client.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/stacking_client.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_move_client.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_types.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/focus_manager.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_observer.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/dragdrop/os_exchange_data.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/events/event.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/ui_base_types.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/canvas.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/font.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h" 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/native_theme/native_theme_aura.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/drag_utils.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/ime/input_method_bridge.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/views_delegate.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/drop_helper.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_aura_window_observer.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/native_widget_delegate.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/root_view.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/tooltip_manager_aura.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_aura_utils.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h" 42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/views/widget/window_reorderer.h" 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/scoped_gdi_object.h" 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/win_util.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util_win.h" 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h" 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 513240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_X11) && !defined(OS_CHROMEOS) 52558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "ui/views/widget/desktop_aura/desktop_root_window_host_x11.h" 53558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 54558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_root_window_host.h" 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, public: 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : delegate_(delegate), 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_(new aura::Window(this)), 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) close_widget_factory_(this), 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) can_activate_(true), 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) destroying_(false), 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_(gfx::kNullCursor), 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) saved_window_state_(ui::SHOW_STATE_DEFAULT) { 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::SetFocusChangeObserver(window_, this); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::SetActivationChangeObserver(window_, this); 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Font NativeWidgetAura::GetWindowTitleFont() { 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NONCLIENTMETRICS ncm; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::GetNonClientMetrics(&ncm); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Font(caption_font); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Font(); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, internal::NativeWidgetPrivate implementation: 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Aura needs to know which desktop (Ash or regular) will manage this widget. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // See Widget::InitParams::context for details. 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(params.parent || params.context); 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_ = params.ownership; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->set_user_data(this); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, params.show_state); 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type == Widget::InitParams::TYPE_BUBBLE) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetHideOnDeactivate(window_, true); 113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch window_->SetTransparent( 114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Init(params.layer_type); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type == Widget::InitParams::TYPE_CONTROL) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Show(); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) delegate_->OnNativeWidgetCreated(false); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds = params.bounds; 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView parent = params.parent; 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView context = params.context; 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!params.child) { 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set up the transient child before the window is added. This way the 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // LayoutManager knows the window has a transient parent. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent->AddTransientChild(window_); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!context) 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) context = parent; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent = NULL; 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetAlwaysOnTop before SetParent so that always-on-top container is used. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetAlwaysOnTop(params.keep_on_top); 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure we have a real |window_bounds|. 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (parent && window_bounds == gfx::Rect()) { 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a parent is specified but no bounds are given, 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // use the origin of the parent's display so that the widget 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be added to the same display as the parent. 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(parent).bounds(); 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.set_origin(bounds.origin()); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (parent) { 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) parent->AddChild(window_); 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetDefaultParentByRootWindow(context->GetRootWindow(), 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_bounds); 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Wait to set the bounds until we have a parent. That way we can know our 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true state/bounds (the LayoutManager may enforce a particular 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // state/bounds). 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMaximized()) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetRestoreBounds(window_, window_bounds); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetBounds(window_bounds); 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->set_ignore_events(!params.accept_events); 161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) can_activate_ = params.can_activate && 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) params.type != Widget::InitParams::TYPE_CONTROL && 163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) params.type != Widget::InitParams::TYPE_TOOLTIP; 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(GetWidget()->GetRootView()); 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_MACOSX) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type != Widget::InitParams::TYPE_TOOLTIP) 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) tooltip_manager_.reset(new views::TooltipManagerAura(window_, GetWidget())); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // !defined(OS_MACOSX) 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (params.type != Widget::InitParams::TYPE_TOOLTIP && 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) params.type != Widget::InitParams::TYPE_POPUP) { 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetDragDropDelegate(window_, this); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::SetActivationDelegate(window_, this); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kCanMaximizeKey, 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->widget_delegate()->CanMaximize()); 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kCanResizeKey, 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->widget_delegate()->CanResize()); 182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_.reset(new WindowReorderer(window_, 184868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GetWidget()->GetRootView())); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldUseNativeFrame() const { 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // There is only one frame type for aura. 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FrameTypeChanged() { 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is called when the Theme has changed; forward the event to the root 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // widget. 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->ThemeChanged(); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetRootView()->SchedulePaint(); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetWidget() { 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const Widget* NativeWidgetAura::GetWidget() const { 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->AsWidget(); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeView NativeWidgetAura::GetNativeView() const { 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget* NativeWidgetAura::GetTopLevelWidget() { 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return native_widget ? native_widget->GetWidget() : NULL; 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const ui::Compositor* NativeWidgetAura::GetCompositor() const { 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->layer()->GetCompositor(); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::Compositor* NativeWidgetAura::GetCompositor() { 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->layer()->GetCompositor(); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)ui::Layer* NativeWidgetAura::GetLayer() { 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return window_->layer(); 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)void NativeWidgetAura::ReorderNativeViews() { 237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) window_reorderer_->ReorderChildWindows(); 238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ViewRemoved(View* view) { 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->ResetTargetViewIfEquals(view); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetNativeWindowProperty(name, value); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_ ? window_->GetNativeWindowProperty(name) : NULL; 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TooltipManager* NativeWidgetAura::GetTooltipManager() const { 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return tooltip_manager_.get(); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCapture() { 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetCapture(); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ReleaseCapture() { 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->ReleaseCapture(); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasCapture() const { 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->HasCapture(); 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)InputMethod* NativeWidgetAura::CreateInputMethod() { 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::RootWindow* root_window = window_->GetRootWindow(); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::InputMethod* host = 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) root_window->GetProperty(aura::client::kRootWindowInputMethodKey); 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return new InputMethodBridge(this, host, true); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return this; 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When centering window, we take the intersection of the host and 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the parent. We assume the root window represents the visible 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // rect of a single screen. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(window_).work_area(); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(window_->GetRootWindow()); 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = work_area.origin(); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &origin); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) work_area.set_origin(origin); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.Intersect(work_area); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |window_|'s transient parent's bounds are big enough to fit it, then we 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // center it with respect to the transient parent. 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->transient_parent()) { 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect transient_parent_rect = window_->transient_parent()-> 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetBoundsInRootWindow(); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.Intersect(work_area); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (transient_parent_rect.height() >= size.height() && 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) transient_parent_rect.width() >= size.width()) 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds = transient_parent_rect; 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds( 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.width(), 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size.height()); 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't size the window bigger than the parent, otherwise the user may not be 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // able to close or move it. 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.AdjustToFit(parent_bounds); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Convert the bounds back relative to the parent. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point origin = window_bounds.origin(); 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window::ConvertPointToTarget(window_->GetRootWindow(), 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent(), &origin); 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.set_origin(origin); 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(window_bounds); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetWindowPlacement( 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* bounds, 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WindowShowState* show_state) const { 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The interface specifies returning restored bounds, not current bounds. 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *bounds = GetRestoredBounds(); 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *show_state = window_->GetProperty(aura::client::kShowStateKey); 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetWindowTitle(const string16& title) { 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->set_title(title); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::ImageSkia& app_icon) { 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Aura doesn't have window icons. 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (modal_type != ui::MODAL_TYPE_NONE) 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, modal_type); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetBoundsInScreen(); 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // View-to-screen coordinate system transformations depend on this returning 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the full window bounds, for example View::ConvertPointToScreen(). 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetBoundsInScreen(); 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetRestoredBounds() const { 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restored bounds should only be relevant if the window is minimized or 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // maximized. However, in some places the code expects GetRestoredBounds() 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to return the current window bounds if the window is not in either state. 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsMinimized() || IsMaximized() || IsFullscreen()) { 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restore bounds are in screen coordinates, no need to convert. 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* restore_bounds = 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->GetProperty(aura::client::kRestoreBoundsKey); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (restore_bounds) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return *restore_bounds; 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetBoundsInScreen(); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::RootWindow* root = window_->GetRootWindow(); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root) { 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::ScreenPositionClient* screen_position_client = 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetScreenPositionClient(root); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (screen_position_client) { 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Display dst_display = 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) screen_position_client->SetBounds(window_, bounds, dst_display); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(bounds); 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetSize(const gfx::Size& size) { 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->parent() && window_->parent() == native_view->parent()) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildAbove(window_, native_view); 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackAtTop() { 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildAtTop(window_); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->parent() && window_->parent() == native_view->parent()) 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->parent()->StackChildBelow(window_, native_view); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetShape(gfx::NativeRegion region) { 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // No need for this. Just delete and ignore. 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete region; 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Close() { 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |window_| may already be deleted by parent window. This can happen 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when this widget is child widget or has transient parent 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and ownership is WIDGET_OWNS_NATIVE_WIDGET. 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_ || 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) { 4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SuppressPaint(); 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Hide(); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!close_widget_factory_.HasWeakPtrs()) { 425c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoop::current()->PostTask( 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FROM_HERE, 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&NativeWidgetAura::CloseNow, 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) close_widget_factory_.GetWeakPtr())); 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::CloseNow() { 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete window_; 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Show() { 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowWithWindowState(ui::SHOW_STATE_INACTIVE); 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Hide() { 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Hide(); 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowMaximizedWithBounds( 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& restored_bounds) { 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetRestoreBounds(window_, restored_bounds); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN) 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, state); 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Show(); 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (can_activate_) { 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (state != ui::SHOW_STATE_INACTIVE) 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Activate(); 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFocus() should be always be called, even for 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SHOW_STATE_INACTIVE. When a frameless modal dialog is created by 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a widget of TYPE_WINDOW_FRAMELESS, Widget::Show() will call into 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this function with the window state SHOW_STATE_INACTIVE, 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetInitialFoucs() has to be called so that the dialog can get focus. 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This also matches NativeWidgetWin which invokes SetInitialFocus 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // regardless of show state. 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetInitialFocus(); 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsVisible() const { 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->IsVisible(); 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Activate() { 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't necessarily have a root window yet. This can happen with 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // constrained windows. 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetRootWindow()) { 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_->GetProperty(aura::client::kDrawAttentionKey)) 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, false); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Deactivate() { 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_); 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsActive() const { 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::client::GetActivationClient(window_->GetRootWindow())-> 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetActiveWindow() == window_; 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Maximize() { 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Minimize() { 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMaximized() const { 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetProperty(aura::client::kShowStateKey) == 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MAXIMIZED; 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsMinimized() const { 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetProperty(aura::client::kShowStateKey) == 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_MINIMIZED; 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::Restore() { 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetFullscreen(bool fullscreen) { 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsFullscreen() == fullscreen) 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; // Nothing to do. 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Save window state before entering full screen so that it could restored 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when exiting full screen. 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (fullscreen) 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty( 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::kShowStateKey, 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::IsFullscreen() const { 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetProperty(aura::client::kShowStateKey) == 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::SHOW_STATE_FULLSCREEN; 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetOpacity(unsigned char opacity) { 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->SetOpacity(opacity / 255.0); 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTIMPLEMENTED(); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::FlashFrame(bool flash) { 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kDrawAttentionKey, flash); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::RunShellDrag(View* view, 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ui::OSExchangeData& data, 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location, 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int operation, 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::DragDropTypes::DragEventSource source) { 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::RunShellDrag(window_, data, location, operation, source); 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_) 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SchedulePaintInRect(rect); 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_ = cursor; 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::CursorClient* cursor_client = 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (cursor_client) 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) cursor_client->SetCursor(cursor); 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)bool NativeWidgetAura::IsMouseEventsEnabled() const { 5727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::CursorClient* cursor_client = 5737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) aura::client::GetCursorClient(window_->GetRootWindow()); 5747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; 5757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 5767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::ClearNativeFocus() { 5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ && client && window_->Contains(client->GetFocusedWindow())) 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) client->ResetFocusWithinActiveWindow(window_); 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Screen::GetScreenFor(GetNativeView())-> 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetDisplayNearestWindow(GetNativeView()).work_area(); 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!value) { 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) active_window_observer_.reset(); 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) active_window_observer_.reset( 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new NativeWidgetAuraWindowObserver(window_, delegate_)); 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( 5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Vector2d& drag_offset, 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Widget::MoveLoopSource source) { 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->parent() && 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetCapture(); 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WindowMoveSource window_move_source = 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) source == Widget::MOVE_LOOP_SOURCE_MOUSE ? 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_MOUSE : 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::WINDOW_MOVE_SOURCE_TOUCH; 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura::client::GetWindowMoveClient(window_->parent())->RunMoveLoop( 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_, drag_offset, window_move_source) == 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::MOVE_SUCCESSFUL) { 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_SUCCESSFUL; 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return Widget::MOVE_LOOP_CANCELED; 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::EndMoveLoop() { 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->parent() && 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())) { 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetWindowMoveClient(window_->parent())->EndMoveLoop(); 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) 629558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return DesktopRootWindowHost::GetNativeTheme(window_); 630558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#else 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ui::NativeThemeAura::instance(); 632558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, views::InputMethodDelegate implementation: 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FocusManager* focus_manager = GetWidget()->GetFocusManager(); 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (key.handled() || !focus_manager) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) focus_manager->OnKeyEvent(key); 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDelegate implementation: 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Size NativeWidgetAura::GetMinimumSize() const { 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetMinimumSize(); 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size NativeWidgetAura::GetMaximumSize() const { 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return delegate_->GetMaximumSize(); 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& new_bounds) { 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.origin() != new_bounds.origin()) 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetMove(); 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (old_bounds.size() != new_bounds.size()) 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return cursor_; 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->GetNonClientComponent(point); 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* child, 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location) { 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (widget_delegate && 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Don't descend into |child| if there is a view with a Layer that contains 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the point and is stacked above |child|s layer. 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<ui::Layer*> Layers; 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Layers& root_layers(delegate_->GetRootLayers()); 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layers.empty()) 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator child_layer_iter( 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), child->layer())); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (child_layer_iter == window_->layer()->children().end()) 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (std::vector<ui::Layer*>::const_reverse_iterator i = root_layers.rbegin(); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != root_layers.rend(); ++i) { 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::Layer* layer = *i; 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (layer->visible() && layer->bounds().Contains(location)) { 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Layers::const_iterator root_layer_iter( 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::find(window_->layer()->children().begin(), 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->layer()->children().end(), layer)); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (root_layer_iter > child_layer_iter) 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::CanFocus() { 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_; 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnCaptureLost() { 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnMouseCaptureLost(); 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetPaint(canvas); 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Repainting with new scale factor will paint the content at the right scale. 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroying() { 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroying(); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the aura::Window is destroyed, we can no longer show tooltips. 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_.reset(); 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowDestroyed() { 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_ = NULL; 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetDestroyed(); 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete this; 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->OnNativeWidgetVisibilityChanged(visible); 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetAura::HasHitTestMask() const { 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate_->HasHitTestMask(); 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(mask); 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->GetHitTestMask(mask); 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_refptr<ui::Texture> NativeWidgetAura::CopyTexture() { 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The layer we create doesn't have an external texture, so this should never 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // get invoked. 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return scoped_refptr<ui::Texture>(); 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, ui::EventHandler implementation: 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (event->is_char()) { 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a ui::InputMethod object is attached to the root window, character 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // events are handled inside the object and are not passed to this function. 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If such object is not attached, character events might be sent (e.g. on 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Windows). In this case, we just skip these. 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Renderer may send a key event back to us if the key event wasn't handled, 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the window may be invisible by that time. 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!window_->IsVisible()) 7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->GetInputMethod()->DispatchKeyEvent(*event); 7742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event->SetHandled(); 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->type() == ui::ET_MOUSEWHEEL) { 7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->handled()) 7822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (tooltip_manager_.get()) 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tooltip_manager_->UpdateTooltip(); 7872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnMouseEvent(event); 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { 7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnScrollEvent(event); 7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnTouchEvent(event); 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(window_->IsVisible()); 8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnGestureEvent(event); 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationDelegate implementation: 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NativeWidgetAura::ShouldActivate() const { 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return can_activate_ && delegate_->CanActivate(); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::ActivationChangeObserver implementation: 8132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowActivated(aura::Window* gained_active, 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_active) { 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(window_ == gained_active || window_ == lost_active); 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetFocusManager()) { 8182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_active) 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->RestoreFocusedView(); 8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else if (window_ == lost_active) 8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetFocusManager()->StoreFocusedView(true); 8222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (IsVisible() && GetWidget()->non_client_view()) 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetWidget()->non_client_view()->SchedulePaint(); 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// NativeWidgetAura, aura::client::FocusChangeObserver: 8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_focus) { 8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (window_ == gained_focus) { 8342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // In aura, it is possible for child native widgets to take input and focus, 8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this differs from the behavior on windows. 8362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) // Null in tests. 8372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnFocus(); 8382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeFocus(lost_focus); 8392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (window_ == lost_focus) { 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // GetInputMethod() recreates the input method if it's previously been 8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destroyed. If we get called during destruction, the input method will be 8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // gone, and creating a new one and telling it that we lost the focus will 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // trigger a DCHECK (the new input method doesn't think that we have the 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // focus and doesn't expect a blur). OnBlur() shouldn't be called during 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the 8462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // case in tests). 8472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!destroying_) { 8482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (GetWidget()->GetInputMethod()) 8492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetWidget()->GetInputMethod()->OnBlur(); 8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 8522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (client) // NULL during destruction of aura::Window. 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delegate_->OnNativeBlur(client->GetFocusedWindow()); 8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, aura::WindowDragDropDelegate implementation: 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), event.source_operations()); 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return last_drop_operation_; 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::OnDragExited() { 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_helper_->OnDragExit(); 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(drop_helper_.get() != NULL); 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return drop_helper_->OnDrop(event.data(), event.location(), 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) last_drop_operation_); 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// NativeWidgetAura, NativeWidget implementation: 8897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)ui::EventHandler* NativeWidgetAura::GetEventHandler() { 8917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return this; 8927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 8937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 8947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, protected: 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetAura::~NativeWidgetAura() { 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) destroying_ = true; 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delete delegate_; 9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CloseNow(); 9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NativeWidgetAura, private: 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetAura::SetInitialFocus() { 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The window does not get keyboard messages unless we focus it. 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!GetWidget()->SetInitialFocus()) 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->Focus(); 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Widget, public: 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::NotifyLocaleChanged() { 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deliberately not implemented. 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 923558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochvoid CloseWindow(aura::Window* window) { 924558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if (window) { 925558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch Widget* widget = Widget::GetWidgetForNativeView(window); 9262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (widget && widget->is_secondary_widget()) 927c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // To avoid the delay in shutdown caused by using Close which may wait 928c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // for animations, use CloseNow. Because this is only used on secondary 929c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // widgets it seems relatively safe to skip the extra processing of 930c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Close. 931c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) widget->CloseNow(); 9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 933558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} 934558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) 935558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochBOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { 936558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch aura::Window* root_window = 937558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostWin::GetContentWindowForHWND(hwnd); 938558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CloseWindow(root_window); 9392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return TRUE; 9402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 942558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch} // namespace 9432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void Widget::CloseAllSecondaryWidgets() { 9462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 9472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); 9482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 949558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 9503240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_X11) && !defined(OS_CHROMEOS) 951558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::vector<aura::Window*> open_windows = 952558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::GetAllOpenWindows(); 953558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch std::for_each(open_windows.begin(), open_windows.end(), CloseWindow); 954558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch DesktopRootWindowHostX11::CleanUpWindowList(); 955558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool Widget::ConvertRect(const Widget* source, 9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Widget* target, 9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect* rect) { 9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace internal { 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// internal::NativeWidgetPrivate, public: 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) internal::NativeWidgetDelegate* delegate) { 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return new NativeWidgetAura(delegate); 9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data()); 9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( 9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeWindow native_window) { 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data()); 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView native_view) { 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window = native_view; 9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* top_level_native_widget = NULL; 9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) while (window) { 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget) 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) top_level_native_widget = native_widget; 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window = window->parent(); 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return top_level_native_widget; 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets* children) { 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Code expects widget for |native_view| to be added to |children|. 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( 10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetNativeWidgetForNativeView(native_view)); 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget && native_widget->GetWidget()) 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) children->insert(native_widget->GetWidget()); 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const aura::Window::Windows& child_windows = native_view->children(); 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (aura::Window::Windows::const_iterator i = child_windows.begin(); 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) i != child_windows.end(); ++i) { 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NativeWidgetAura* native_widget = 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<NativeWidgetAura*>(GetNativeWidgetForNativeView(*i)); 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (native_widget) 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) children->insert(native_widget->GetWidget()); 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView new_parent) { 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(native_view != new_parent); 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView previous_parent = native_view->parent(); 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (previous_parent == new_parent) 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Widget::Widgets widgets; 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetAllChildWidgets(native_view, &widgets); 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // First notify all the widgets that they are being disassociated 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from their previous parent. 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (new_parent) { 10422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) new_parent->AddChild(native_view); 10432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 10442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The following looks weird, but it's the equivalent of what aura has 10452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always done. (The previous behaviour of aura::Window::SetParent() used 10462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // NULL as a special value that meant ask the StackingClient where things 10472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // should go.) 10482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 10492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This probably isn't strictly correct, but its an invariant that a Window 10502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in use will be attached to a RootWindow, so we can't just call 10512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // RemoveChild here. The only possible thing that could assign a RootWindow 10522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in this case is the stacking client of the current RootWindow. This 10532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // matches our previous behaviour; the global stacking client would almost 10542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // always reattach the window to the same RootWindow. 10552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::RootWindow* root_window = native_view->GetRootWindow(); 10562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) native_view->SetDefaultParentByRootWindow( 10572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) root_window, root_window->GetBoundsInScreen()); 10582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // And now, notify them that they have a brand new parent. 10615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (Widget::Widgets::iterator it = widgets.begin(); 10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != widgets.end(); ++it) { 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); 10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsMouseButtonDown() { 10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::Env::GetInstance()->is_mouse_button_down(); 10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool NativeWidgetPrivate::IsTouchDown() { 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return aura::Env::GetInstance()->is_touch_down(); 10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace internal 10785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace views 1079