Chromium Code Reviews| Index: ui/views/widget/desktop_android/desktop_native_widget_android.cc |
| diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/desktop_android/desktop_native_widget_android.cc |
| similarity index 29% |
| copy from ui/views/widget/native_widget_aura.cc |
| copy to ui/views/widget/desktop_android/desktop_native_widget_android.cc |
| index 8099626710db18abf5751e2c015403307ec4ff92..3f07c9817e08a55b0ed15421b78d418d37ad2ab1 100644 |
| --- a/ui/views/widget/native_widget_aura.cc |
| +++ b/ui/views/widget/desktop_android/desktop_native_widget_android.cc |
| @@ -1,14 +1,16 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ui/views/widget/native_widget_aura.h" |
| +#include "ui/views/widget/desktop_android/desktop_native_widget_android.h" |
| #include "base/bind.h" |
| +#include "base/run_loop.h" |
| #include "base/strings/string_util.h" |
| #include "third_party/skia/include/core/SkRegion.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/cursor_client.h" |
| +#include "ui/aura/client/default_capture_client.h" |
| #include "ui/aura/client/focus_client.h" |
| #include "ui/aura/client/screen_position_client.h" |
| #include "ui/aura/client/window_tree_client.h" |
| @@ -27,51 +29,99 @@ |
| #include "ui/native_theme/native_theme_aura.h" |
| #include "ui/views/drag_utils.h" |
| #include "ui/views/views_delegate.h" |
| -#include "ui/views/widget/drop_helper.h" |
| +#include "ui/views/widget/desktop_android/android_focus_rules.h" |
| +#include "ui/views/widget/native_widget_aura.h" |
| #include "ui/views/widget/native_widget_delegate.h" |
| #include "ui/views/widget/root_view.h" |
| #include "ui/views/widget/tooltip_manager_aura.h" |
| #include "ui/views/widget/widget_aura_utils.h" |
| #include "ui/views/widget/widget_delegate.h" |
| #include "ui/views/widget/window_reorderer.h" |
| +#include "ui/wm/core/default_activation_client.h" |
| +#include "ui/wm/core/default_screen_position_client.h" |
| +#include "ui/wm/core/focus_controller.h" |
| #include "ui/wm/core/shadow_types.h" |
| #include "ui/wm/core/window_animations.h" |
| #include "ui/wm/core/window_util.h" |
| #include "ui/wm/public/activation_client.h" |
| +#include "ui/wm/public/dispatcher_client.h" |
| #include "ui/wm/public/drag_drop_client.h" |
| #include "ui/wm/public/window_move_client.h" |
| #include "ui/wm/public/window_types.h" |
| -#if defined(OS_WIN) |
| -#include "base/win/scoped_gdi_object.h" |
| -#include "base/win/win_util.h" |
| -#include "ui/base/l10n/l10n_util_win.h" |
| -#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" |
| -#endif |
| +// TODO(bshe): Most of the code is copied from DesktopNativeWidgetAura. There |
|
mfomitchev
2015/11/11 22:40:32
DesktopNativeWidgetAura or NativeWidgetAura?
bshe
2015/11/12 16:19:40
Updated comment.
|
| +// will be more differences overtime. For upstreaming purpose, keep the change |
| +// minimal. |
| +namespace { |
| -#if defined(USE_X11) && !defined(OS_CHROMEOS) |
| -#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| -#endif |
| +class DesktopNativeWidgetAndroidWindowTreeClient |
| + : public aura::client::WindowTreeClient { |
| + public: |
| + explicit DesktopNativeWidgetAndroidWindowTreeClient(aura::Window* root_window) |
| + : root_window_(root_window) { |
| + aura::client::SetWindowTreeClient(root_window_, this); |
| + } |
| + ~DesktopNativeWidgetAndroidWindowTreeClient() override { |
| + aura::client::SetWindowTreeClient(root_window_, NULL); |
| + } |
| -#if !defined(OS_CHROMEOS) |
| -#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| -#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" |
| -#endif |
| + // Overridden from client::WindowTreeClient: |
| + aura::Window* GetDefaultParent(aura::Window* context, |
| + aura::Window* window, |
| + const gfx::Rect& bounds) override { |
| + return root_window_; |
| + } |
| -namespace views { |
| + private: |
| + aura::Window* root_window_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAndroidWindowTreeClient); |
| +}; |
| + |
| +// TODO(bshe|jonross): Get rid of nested message loop once crbug.com/523680 is |
| +// fiexed. |
| +class AndroidDispatcherClient : public aura::client::DispatcherClient { |
| + public: |
| + AndroidDispatcherClient() : dispatcher_(nullptr) {} |
| + ~AndroidDispatcherClient() override {} |
| + |
| + base::MessagePumpDispatcher* dispatcher() { return dispatcher_; } |
| + |
| + // aura::client::DispatcherClient: |
| + void PrepareNestedLoopClosures(base::MessagePumpDispatcher* dispatcher, |
| + base::Closure* run_closure, |
| + base::Closure* quit_closure) override { |
| + scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); |
| + *quit_closure = run_loop->QuitClosure(); |
| + *run_closure = |
| + base::Bind(&AndroidDispatcherClient::RunNestedDispatcher, |
| + base::Unretained(this), base::Passed(&run_loop), dispatcher); |
| + } |
| -namespace { |
| + private: |
| + void RunNestedDispatcher(scoped_ptr<base::RunLoop> run_loop, |
| + base::MessagePumpDispatcher* dispatcher) { |
| + base::AutoReset<base::MessagePumpDispatcher*> reset_dispatcher(&dispatcher_, |
| + dispatcher); |
| + base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
| + base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
| + run_loop->Run(); |
| + } |
| -void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { |
| - window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); |
| -} |
| + base::MessagePumpDispatcher* dispatcher_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AndroidDispatcherClient); |
| +}; |
| } // namespace |
| +namespace views { |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, public: |
| +// DesktopNativeWidgetAndroid, public |
| -NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
| +DesktopNativeWidgetAndroid::DesktopNativeWidgetAndroid( |
| + internal::NativeWidgetDelegate* delegate) |
| : delegate_(delegate), |
| window_(new aura::Window(this)), |
| ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| @@ -83,92 +133,48 @@ NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
| aura::client::SetActivationChangeObserver(window_, this); |
| } |
| -// static |
| -void NativeWidgetAura::RegisterNativeWidgetForWindow( |
| - internal::NativeWidgetPrivate* native_widget, |
| - aura::Window* window) { |
| - window->set_user_data(native_widget); |
| -} |
| - |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, internal::NativeWidgetPrivate implementation: |
| - |
| -void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { |
| - // Aura needs to know which desktop (Ash or regular) will manage this widget. |
| - // See Widget::InitParams::context for details. |
| - DCHECK(params.parent || params.context); |
| +// DesktopNativeWidgetAndroid, DesktopNativeWidgetAndroid implementation: |
|
mfomitchev
2015/11/11 22:40:32
This header doesn't make much sense to me. The pre
bshe
2015/11/12 16:19:40
Sorry. It is probably a search and replace error.
|
| +void DesktopNativeWidgetAndroid::InitNativeWidget( |
| + const Widget::InitParams& params) { |
| ownership_ = params.ownership; |
| + NativeWidgetAura::RegisterNativeWidgetForWindow(this, window_); |
| - RegisterNativeWidgetForWindow(this, window_); |
| window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); |
| - window_->SetProperty(aura::client::kShowStateKey, params.show_state); |
| - if (params.type == Widget::InitParams::TYPE_BUBBLE) |
| - aura::client::SetHideOnDeactivate(window_, true); |
| - window_->SetTransparent( |
| - params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW); |
| window_->Init(params.layer_type); |
| - if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_NONE) |
| - SetShadowType(window_, wm::SHADOW_TYPE_NONE); |
| - else if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_DROP) |
| - SetShadowType(window_, wm::SHADOW_TYPE_RECTANGULAR); |
| - if (params.type == Widget::InitParams::TYPE_CONTROL) |
| - window_->Show(); |
| + wm::SetShadowType(window_, wm::SHADOW_TYPE_NONE); |
| + window_->Show(); |
| - delegate_->OnNativeWidgetCreated(false); |
| + // TODO(bshe): Get rid of the hard coded size. Tracked in crbug.com/551923. |
| + host_.reset(aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600))); |
| + host_->InitHost(); |
| + host_->AddObserver(this); |
| - gfx::Rect window_bounds = params.bounds; |
| - gfx::NativeView parent = params.parent; |
| - gfx::NativeView context = params.context; |
| - if (!params.child) { |
| - // Set up the transient child before the window is added. This way the |
| - // LayoutManager knows the window has a transient parent. |
| - if (parent && parent->type() != ui::wm::WINDOW_TYPE_UNKNOWN) { |
| - wm::AddTransientChild(parent, window_); |
| - if (!context) |
| - context = parent; |
| - parent = NULL; |
| - } |
| - // SetAlwaysOnTop before SetParent so that always-on-top container is used. |
| - SetAlwaysOnTop(params.keep_on_top); |
| - // Make sure we have a real |window_bounds|. |
| - if (parent && window_bounds == gfx::Rect()) { |
| - // If a parent is specified but no bounds are given, |
| - // use the origin of the parent's display so that the widget |
| - // will be added to the same display as the parent. |
| - gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> |
| - GetDisplayNearestWindow(parent).bounds(); |
| - window_bounds.set_origin(bounds.origin()); |
| - } |
| - } |
| + window_tree_client_.reset( |
| + new DesktopNativeWidgetAndroidWindowTreeClient(host_->window())); |
| - // Set properties before adding to the parent so that its layout manager sees |
| - // the correct values. |
| - OnSizeConstraintsChanged(); |
| + focus_client_.reset(new wm::FocusController(new AndroidFocusRules)); |
| + aura::client::SetFocusClient(host_->window(), focus_client_.get()); |
| + host_->window()->AddPreTargetHandler(focus_client_.get()); |
| - if (parent) { |
| - parent->AddChild(window_); |
| - } else { |
| - aura::client::ParentWindowWithContext( |
| - window_, context->GetRootWindow(), window_bounds); |
| - } |
| + new wm::DefaultActivationClient(host_->window()); |
| - // Start observing property changes. |
| - window_->AddObserver(this); |
| + capture_client_.reset( |
| + new aura::client::DefaultCaptureClient(host_->window())); |
| + |
| + screen_position_client_.reset(new wm::DefaultScreenPositionClient); |
| + aura::client::SetScreenPositionClient(host_->window(), |
| + screen_position_client_.get()); |
| + dispatcher_client_.reset(new AndroidDispatcherClient); |
| + aura::client::SetDispatcherClient(host_->window(), dispatcher_client_.get()); |
| + |
| + delegate_->OnNativeWidgetCreated(false); |
| - // Wait to set the bounds until we have a parent. That way we can know our |
| - // true state/bounds (the LayoutManager may enforce a particular |
| - // state/bounds). |
| - if (IsMaximized()) |
| - SetRestoreBounds(window_, window_bounds); |
| - else |
| - SetBounds(window_bounds); |
| - window_->set_ignore_events(!params.accept_events); |
| DCHECK(GetWidget()->GetRootView()); |
| if (params.type != Widget::InitParams::TYPE_TOOLTIP) |
| tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); |
| - drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); |
| if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
| params.type != Widget::InitParams::TYPE_POPUP) { |
| aura::client::SetDragDropDelegate(window_, this); |
| @@ -176,514 +182,385 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { |
| aura::client::SetActivationDelegate(window_, this); |
| - window_reorderer_.reset(new WindowReorderer(window_, |
| - GetWidget()->GetRootView())); |
| + host_->window()->AddChild(window_); |
| + window_reorderer_.reset( |
| + new WindowReorderer(window_, GetWidget()->GetRootView())); |
| + |
| + // TODO(bshe): figure out how to add cursor manager, drag drop client and all |
| + // the necessary parts that exists in desktop_native_widget_aura. |
| } |
| -NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { |
| - return NULL; |
| +NonClientFrameView* DesktopNativeWidgetAndroid::CreateNonClientFrameView() { |
| + NOTIMPLEMENTED(); |
| + return nullptr; |
| } |
| -bool NativeWidgetAura::ShouldUseNativeFrame() const { |
| +bool DesktopNativeWidgetAndroid::ShouldUseNativeFrame() const { |
| // There is only one frame type for aura. |
| return false; |
| } |
| -bool NativeWidgetAura::ShouldWindowContentsBeTransparent() const { |
| +bool DesktopNativeWidgetAndroid::ShouldWindowContentsBeTransparent() const { |
| + NOTIMPLEMENTED(); |
| return false; |
| } |
| -void NativeWidgetAura::FrameTypeChanged() { |
| - // This is called when the Theme has changed; forward the event to the root |
| - // widget. |
| - GetWidget()->ThemeChanged(); |
| - GetWidget()->GetRootView()->SchedulePaint(); |
| +void DesktopNativeWidgetAndroid::FrameTypeChanged() { |
| + NOTIMPLEMENTED(); |
| } |
| -Widget* NativeWidgetAura::GetWidget() { |
| +Widget* DesktopNativeWidgetAndroid::GetWidget() { |
| return delegate_->AsWidget(); |
| } |
| -const Widget* NativeWidgetAura::GetWidget() const { |
| +const Widget* DesktopNativeWidgetAndroid::GetWidget() const { |
| return delegate_->AsWidget(); |
| } |
| -gfx::NativeView NativeWidgetAura::GetNativeView() const { |
| +gfx::NativeView DesktopNativeWidgetAndroid::GetNativeView() const { |
| return window_; |
| } |
| -gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { |
| +gfx::NativeWindow DesktopNativeWidgetAndroid::GetNativeWindow() const { |
| return window_; |
| } |
| -Widget* NativeWidgetAura::GetTopLevelWidget() { |
| - NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); |
| - return native_widget ? native_widget->GetWidget() : NULL; |
| +Widget* DesktopNativeWidgetAndroid::GetTopLevelWidget() { |
| + return GetWidget(); |
| } |
| -const ui::Compositor* NativeWidgetAura::GetCompositor() const { |
| - return window_ ? window_->layer()->GetCompositor() : NULL; |
| +const ui::Compositor* DesktopNativeWidgetAndroid::GetCompositor() const { |
| + return host_->compositor(); |
| } |
| -const ui::Layer* NativeWidgetAura::GetLayer() const { |
| - return window_ ? window_->layer() : NULL; |
| +const ui::Layer* DesktopNativeWidgetAndroid::GetLayer() const { |
| + return GetNativeWindow()->layer(); |
| } |
| -void NativeWidgetAura::ReorderNativeViews() { |
| +void DesktopNativeWidgetAndroid::ReorderNativeViews() { |
| window_reorderer_->ReorderChildWindows(); |
| } |
| -void NativeWidgetAura::ViewRemoved(View* view) { |
| - DCHECK(drop_helper_.get() != NULL); |
| - drop_helper_->ResetTargetViewIfEquals(view); |
| +void DesktopNativeWidgetAndroid::ViewRemoved(View* view) { |
| + // TODO: Implement drag and drop. crbug.com/554029. |
|
mfomitchev
2015/11/11 22:40:32
TODO(bshe)
bshe
2015/11/12 16:19:40
Done.
|
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { |
| - if (window_) |
| - window_->SetNativeWindowProperty(name, value); |
| +void DesktopNativeWidgetAndroid::SetNativeWindowProperty(const char* name, |
| + void* value) { |
| + GetNativeWindow()->SetNativeWindowProperty(name, value); |
| } |
| -void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { |
| - return window_ ? window_->GetNativeWindowProperty(name) : NULL; |
| +void* DesktopNativeWidgetAndroid::GetNativeWindowProperty( |
| + const char* name) const { |
| + return GetNativeWindow()->GetNativeWindowProperty(name); |
| } |
| -TooltipManager* NativeWidgetAura::GetTooltipManager() const { |
| +TooltipManager* DesktopNativeWidgetAndroid::GetTooltipManager() const { |
| return tooltip_manager_.get(); |
| } |
| -void NativeWidgetAura::SetCapture() { |
| - if (window_) |
| - window_->SetCapture(); |
| +void DesktopNativeWidgetAndroid::SetCapture() { |
| + GetNativeWindow()->SetCapture(); |
| } |
| -void NativeWidgetAura::ReleaseCapture() { |
| - if (window_) |
| - window_->ReleaseCapture(); |
| +void DesktopNativeWidgetAndroid::ReleaseCapture() { |
| + GetNativeWindow()->ReleaseCapture(); |
| } |
| -bool NativeWidgetAura::HasCapture() const { |
| - return window_ && window_->HasCapture(); |
| +bool DesktopNativeWidgetAndroid::HasCapture() const { |
| + return GetNativeWindow()->HasCapture(); |
| } |
| -ui::InputMethod* NativeWidgetAura::GetInputMethod() { |
| - if (!window_) |
| - return nullptr; |
| - aura::Window* root_window = window_->GetRootWindow(); |
| - return root_window ? root_window->GetHost()->GetInputMethod() : nullptr; |
| +ui::InputMethod* DesktopNativeWidgetAndroid::GetInputMethod() { |
| + return host_->GetInputMethod(); |
| } |
| -void NativeWidgetAura::CenterWindow(const gfx::Size& size) { |
| - if (!window_) |
| - return; |
| - |
| - gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); |
| - // When centering window, we take the intersection of the host and |
| - // the parent. We assume the root window represents the visible |
| - // rect of a single screen. |
| - gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> |
| - GetDisplayNearestWindow(window_).work_area(); |
| - |
| - aura::client::ScreenPositionClient* screen_position_client = |
| - aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
| - if (screen_position_client) { |
| - gfx::Point origin = work_area.origin(); |
| - screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), |
| - &origin); |
| - work_area.set_origin(origin); |
| - } |
| - |
| - parent_bounds.Intersect(work_area); |
| - |
| - // If |window_|'s transient parent's bounds are big enough to fit it, then we |
| - // center it with respect to the transient parent. |
| - if (wm::GetTransientParent(window_)) { |
| - gfx::Rect transient_parent_rect = |
| - wm::GetTransientParent(window_)->GetBoundsInRootWindow(); |
| - transient_parent_rect.Intersect(work_area); |
| - if (transient_parent_rect.height() >= size.height() && |
| - transient_parent_rect.width() >= size.width()) |
| - parent_bounds = transient_parent_rect; |
| - } |
| - |
| - gfx::Rect window_bounds( |
| - parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, |
| - parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, |
| - size.width(), |
| - size.height()); |
| - // Don't size the window bigger than the parent, otherwise the user may not be |
| - // able to close or move it. |
| - window_bounds.AdjustToFit(parent_bounds); |
| - |
| - // Convert the bounds back relative to the parent. |
| - gfx::Point origin = window_bounds.origin(); |
| - aura::Window::ConvertPointToTarget(window_->GetRootWindow(), |
| - window_->parent(), &origin); |
| - window_bounds.set_origin(origin); |
| - window_->SetBounds(window_bounds); |
| +void DesktopNativeWidgetAndroid::CenterWindow(const gfx::Size& size) { |
| + // TODO(bshe): Implement this. See crbug.com/554208. |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::GetWindowPlacement( |
| +void DesktopNativeWidgetAndroid::GetWindowPlacement( |
| gfx::Rect* bounds, |
| ui::WindowShowState* show_state) const { |
| - // The interface specifies returning restored bounds, not current bounds. |
| - *bounds = GetRestoredBounds(); |
| - *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey) : |
| - ui::SHOW_STATE_DEFAULT; |
| + // TODO(bshe): Implement this. See crbug.com/554208. |
| + NOTIMPLEMENTED(); |
| } |
| -bool NativeWidgetAura::SetWindowTitle(const base::string16& title) { |
| - if (!window_) |
| - return false; |
| - if (window_->title() == title) |
| +bool DesktopNativeWidgetAndroid::SetWindowTitle(const base::string16& title) { |
| + if (GetNativeWindow()->title() == title) |
| return false; |
| - window_->SetTitle(title); |
| + GetNativeWindow()->SetTitle(title); |
| return true; |
| } |
| -void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, |
| - const gfx::ImageSkia& app_icon) { |
| - // Aura doesn't have window icons. |
| +void DesktopNativeWidgetAndroid::SetWindowIcons( |
| + const gfx::ImageSkia& window_icon, |
| + const gfx::ImageSkia& app_icon) { |
| + // TODO(bshe): Implement this. See crbug.com/554208. |
|
mfomitchev
2015/11/11 22:40:32
Does this window icon functionality really fall un
bshe
2015/11/12 16:19:40
Done.
|
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { |
| +void DesktopNativeWidgetAndroid::InitModalType(ui::ModalType modal_type) { |
| if (modal_type != ui::MODAL_TYPE_NONE) |
|
mfomitchev
2015/11/11 22:40:32
Perhaps this should just be NOTIMPLEMENTED()? Havi
bshe
2015/11/12 16:19:40
Done.
|
| window_->SetProperty(aura::client::kModalKey, modal_type); |
| } |
| -gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { |
| - return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); |
| +gfx::Rect DesktopNativeWidgetAndroid::GetWindowBoundsInScreen() const { |
| + return GetNativeWindow()->GetBoundsInScreen(); |
| } |
| -gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { |
| +gfx::Rect DesktopNativeWidgetAndroid::GetClientAreaBoundsInScreen() const { |
| // View-to-screen coordinate system transformations depend on this returning |
| // the full window bounds, for example View::ConvertPointToScreen(). |
| - return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); |
| -} |
| - |
| -gfx::Rect NativeWidgetAura::GetRestoredBounds() const { |
| - if (!window_) |
| - return gfx::Rect(); |
| - |
| - // Restored bounds should only be relevant if the window is minimized, |
| - // maximized, fullscreen or docked. However, in some places the code expects |
| - // GetRestoredBounds() to return the current window bounds if the window is |
| - // not in either state. |
| - if (IsMinimized() || IsMaximized() || IsFullscreen()) { |
| - // Restore bounds are in screen coordinates, no need to convert. |
| - gfx::Rect* restore_bounds = |
| - window_->GetProperty(aura::client::kRestoreBoundsKey); |
| - if (restore_bounds) |
| - return *restore_bounds; |
| - } |
| - gfx::Rect bounds = window_->GetBoundsInScreen(); |
| - if (IsDocked()) { |
| - // Restore bounds are in screen coordinates, no need to convert. |
| - gfx::Rect* restore_bounds = |
| - window_->GetProperty(aura::client::kRestoreBoundsKey); |
| - // Use current window horizontal offset origin in order to preserve docked |
| - // alignment but preserve restored size and vertical offset for the time |
| - // when the |window_| gets undocked. |
| - if (restore_bounds) { |
| - bounds.set_size(restore_bounds->size()); |
| - bounds.set_y(restore_bounds->y()); |
| - } |
| - } |
| - return bounds; |
| + return GetNativeWindow()->GetBoundsInScreen(); |
| } |
| -void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { |
| - if (!window_) |
| - return; |
| +gfx::Rect DesktopNativeWidgetAndroid::GetRestoredBounds() const { |
| + // TODO(bshe): Implement this. See crbug.com/554208. |
| + NOTIMPLEMENTED(); |
| + return gfx::Rect(); |
| +} |
| - aura::Window* root = window_->GetRootWindow(); |
| - if (root) { |
| - aura::client::ScreenPositionClient* screen_position_client = |
| - aura::client::GetScreenPositionClient(root); |
| - if (screen_position_client) { |
| - gfx::Display dst_display = |
| - gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); |
| - screen_position_client->SetBounds(window_, bounds, dst_display); |
| - return; |
| - } |
| - } |
| - window_->SetBounds(bounds); |
| +void DesktopNativeWidgetAndroid::SetBounds(const gfx::Rect& bounds) { |
| + host_->SetBounds(bounds); |
|
mfomitchev
2015/11/11 22:40:33
Presumably, we'd need to resize the SurfaceView to
bshe
2015/11/12 16:19:40
Added a TODO.
|
| } |
| -void NativeWidgetAura::SetSize(const gfx::Size& size) { |
| - if (window_) |
| - window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
| +void DesktopNativeWidgetAndroid::SetSize(const gfx::Size& size) { |
| + gfx::Rect bounds = host_->GetBounds(); |
| + SetBounds(gfx::Rect(bounds.origin(), size)); |
| } |
| -void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { |
| - if (window_ && window_->parent() && |
| - window_->parent() == native_view->parent()) |
| - window_->parent()->StackChildAbove(window_, native_view); |
| +void DesktopNativeWidgetAndroid::StackAbove(gfx::NativeView native_view) { |
| + // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::StackAtTop() { |
| - if (window_) |
| - window_->parent()->StackChildAtTop(window_); |
| +void DesktopNativeWidgetAndroid::StackAtTop() { |
| + // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { |
| - if (window_ && window_->parent() && |
| - window_->parent() == native_view->parent()) |
| - window_->parent()->StackChildBelow(window_, native_view); |
| +void DesktopNativeWidgetAndroid::StackBelow(gfx::NativeView native_view) { |
| + // TODO(bshe): Implements window stacking logic. See crbug.com/554047 |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::SetShape(SkRegion* region) { |
| - if (window_) |
| - window_->layer()->SetAlphaShape(make_scoped_ptr(region)); |
| - else |
| - delete region; |
| -} |
| - |
| -void NativeWidgetAura::Close() { |
| - // |window_| may already be deleted by parent window. This can happen |
| - // when this widget is child widget or has transient parent |
| - // and ownership is WIDGET_OWNS_NATIVE_WIDGET. |
| - DCHECK(window_ || |
| - ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); |
| - if (window_) { |
| - window_->SuppressPaint(); |
| - Hide(); |
| - window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
| - } |
| +void DesktopNativeWidgetAndroid::SetShape(SkRegion* region) { |
| + GetNativeWindow()->layer()->SetAlphaShape(make_scoped_ptr(region)); |
| +} |
| + |
| +void DesktopNativeWidgetAndroid::Close() { |
| + // TODO(bshe): This might not be right. See crbug.com/554259. |
| + DCHECK(ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); |
| + GetNativeWindow()->SuppressPaint(); |
| + Hide(); |
| + GetNativeWindow()->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); |
| if (!close_widget_factory_.HasWeakPtrs()) { |
| base::MessageLoop::current()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&NativeWidgetAura::CloseNow, |
| - close_widget_factory_.GetWeakPtr())); |
| + FROM_HERE, base::Bind(&DesktopNativeWidgetAndroid::CloseNow, |
| + close_widget_factory_.GetWeakPtr())); |
| } |
| } |
| -void NativeWidgetAura::CloseNow() { |
| +void DesktopNativeWidgetAndroid::CloseNow() { |
| + // TODO(bshe): This might not be right. See crbug.com/554259. |
| + host_->RemoveObserver(this); |
| + host_.reset(); |
| delete window_; |
| } |
| -void NativeWidgetAura::Show() { |
| +void DesktopNativeWidgetAndroid::Show() { |
| ShowWithWindowState(ui::SHOW_STATE_NORMAL); |
| } |
| -void NativeWidgetAura::Hide() { |
| - if (window_) |
| - window_->Hide(); |
| +void DesktopNativeWidgetAndroid::Hide() { |
| + host_->Hide(); |
| + GetNativeWindow()->Hide(); |
| } |
| -void NativeWidgetAura::ShowMaximizedWithBounds( |
| +void DesktopNativeWidgetAndroid::ShowMaximizedWithBounds( |
| const gfx::Rect& restored_bounds) { |
| - SetRestoreBounds(window_, restored_bounds); |
| - ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { |
| - if (!window_) |
| - return; |
| - |
| - if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN || |
| - state == ui::SHOW_STATE_DOCKED) { |
| - window_->SetProperty(aura::client::kShowStateKey, state); |
| - } |
| - window_->Show(); |
| - if (delegate_->CanActivate()) { |
| - if (state != ui::SHOW_STATE_INACTIVE) |
| - Activate(); |
| - // SetInitialFocus() should be always be called, even for |
| - // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will |
| - // do the right thing. |
| - SetInitialFocus(state); |
| - } |
| +void DesktopNativeWidgetAndroid::ShowWithWindowState( |
| + ui::WindowShowState state) { |
| + NOTIMPLEMENTED(); |
| } |
| -bool NativeWidgetAura::IsVisible() const { |
| - return window_ && window_->IsVisible(); |
| +bool DesktopNativeWidgetAndroid::IsVisible() const { |
| + return GetNativeWindow()->IsVisible(); |
| } |
| -void NativeWidgetAura::Activate() { |
| - if (!window_) |
| - return; |
| - |
| - // We don't necessarily have a root window yet. This can happen with |
| - // constrained windows. |
| - if (window_->GetRootWindow()) { |
| - aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( |
| - window_); |
| - } |
| - if (window_->GetProperty(aura::client::kDrawAttentionKey)) |
| - window_->SetProperty(aura::client::kDrawAttentionKey, false); |
| +void DesktopNativeWidgetAndroid::Activate() { |
| + aura::client::GetActivationClient(host_->window()) |
| + ->ActivateWindow(GetNativeWindow()); |
| } |
| -void NativeWidgetAura::Deactivate() { |
| - if (!window_) |
| - return; |
| - aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( |
| - window_); |
| +void DesktopNativeWidgetAndroid::Deactivate() { |
| + aura::client::GetActivationClient(host_->window()) |
| + ->DeactivateWindow(GetNativeWindow()); |
| } |
| -bool NativeWidgetAura::IsActive() const { |
| - return window_ && wm::IsActiveWindow(window_); |
| +bool DesktopNativeWidgetAndroid::IsActive() const { |
| + return wm::IsActiveWindow(GetNativeWindow()); |
| } |
| -void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { |
| - if (window_) |
| - window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top); |
| +void DesktopNativeWidgetAndroid::SetAlwaysOnTop(bool on_top) { |
| + GetNativeWindow()->SetProperty(aura::client::kAlwaysOnTopKey, on_top); |
| } |
| -bool NativeWidgetAura::IsAlwaysOnTop() const { |
| - return window_ && window_->GetProperty(aura::client::kAlwaysOnTopKey); |
| +bool DesktopNativeWidgetAndroid::IsAlwaysOnTop() const { |
| + return GetNativeWindow()->GetProperty(aura::client::kAlwaysOnTopKey); |
| } |
| -void NativeWidgetAura::SetVisibleOnAllWorkspaces(bool always_visible) { |
| - // Not implemented on chromeos or for child widgets. |
| +void DesktopNativeWidgetAndroid::SetVisibleOnAllWorkspaces( |
| + bool always_visible) { |
| + // TODO(bshe): Implement this. See crbug.com/554208. |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::Maximize() { |
| - if (window_) |
| - window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| +void DesktopNativeWidgetAndroid::Maximize() { |
| + GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
|
mfomitchev
2015/11/11 22:40:33
Windows sizing functionality should be NOTIMPLEMEN
bshe
2015/11/12 16:19:40
Done.
|
| + ui::SHOW_STATE_MAXIMIZED); |
| } |
| -void NativeWidgetAura::Minimize() { |
| - if (window_) |
| - window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| +void DesktopNativeWidgetAndroid::Minimize() { |
| + GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
| + ui::SHOW_STATE_MINIMIZED); |
| } |
| -bool NativeWidgetAura::IsMaximized() const { |
| - return window_ && window_->GetProperty(aura::client::kShowStateKey) == |
| - ui::SHOW_STATE_MAXIMIZED; |
| +bool DesktopNativeWidgetAndroid::IsMaximized() const { |
| + return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
| + ui::SHOW_STATE_MAXIMIZED; |
| } |
| -bool NativeWidgetAura::IsMinimized() const { |
| - return window_ && window_->GetProperty(aura::client::kShowStateKey) == |
| - ui::SHOW_STATE_MINIMIZED; |
| +bool DesktopNativeWidgetAndroid::IsMinimized() const { |
| + return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
| + ui::SHOW_STATE_MINIMIZED; |
| } |
| -void NativeWidgetAura::Restore() { |
| - if (window_) |
| - window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| +void DesktopNativeWidgetAndroid::Restore() { |
| + GetNativeWindow()->SetProperty(aura::client::kShowStateKey, |
| + ui::SHOW_STATE_NORMAL); |
| } |
| -void NativeWidgetAura::SetFullscreen(bool fullscreen) { |
| - if (!window_ || IsFullscreen() == fullscreen) |
| +void DesktopNativeWidgetAndroid::SetFullscreen(bool fullscreen) { |
| + if (IsFullscreen() == fullscreen) |
| return; // Nothing to do. |
| // Save window state before entering full screen so that it could restored |
| // when exiting full screen. |
| - if (fullscreen) |
| - saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); |
| + if (fullscreen) { |
| + saved_window_state_ = |
| + GetNativeWindow()->GetProperty(aura::client::kShowStateKey); |
| + } |
| - window_->SetProperty( |
| + GetNativeWindow()->SetProperty( |
| aura::client::kShowStateKey, |
| fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); |
| } |
| -bool NativeWidgetAura::IsFullscreen() const { |
| - return window_ && window_->GetProperty(aura::client::kShowStateKey) == |
| - ui::SHOW_STATE_FULLSCREEN; |
| +bool DesktopNativeWidgetAndroid::IsFullscreen() const { |
| + return GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == |
| + ui::SHOW_STATE_FULLSCREEN; |
| } |
| -void NativeWidgetAura::SetOpacity(unsigned char opacity) { |
| - if (window_) |
| - window_->layer()->SetOpacity(opacity / 255.0); |
| +void DesktopNativeWidgetAndroid::SetOpacity(unsigned char opacity) { |
| + GetNativeWindow()->layer()->SetOpacity(opacity / 255.0); |
| } |
| -void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { |
| +void DesktopNativeWidgetAndroid::SetUseDragFrame(bool use_drag_frame) { |
| NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::FlashFrame(bool flash) { |
| - if (window_) |
| - window_->SetProperty(aura::client::kDrawAttentionKey, flash); |
| +void DesktopNativeWidgetAndroid::FlashFrame(bool flash) { |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::RunShellDrag(View* view, |
| - const ui::OSExchangeData& data, |
| - const gfx::Point& location, |
| - int operation, |
| - ui::DragDropTypes::DragEventSource source) { |
| - if (window_) |
| - views::RunShellDrag(window_, data, location, operation, source); |
| +void DesktopNativeWidgetAndroid::RunShellDrag( |
| + View* view, |
| + const ui::OSExchangeData& data, |
| + const gfx::Point& location, |
| + int operation, |
| + ui::DragDropTypes::DragEventSource source) { |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { |
| - if (window_) |
| - window_->SchedulePaintInRect(rect); |
| +void DesktopNativeWidgetAndroid::SchedulePaintInRect(const gfx::Rect& rect) { |
| + GetNativeWindow()->SchedulePaintInRect(rect); |
| } |
| -void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { |
| +void DesktopNativeWidgetAndroid::SetCursor(gfx::NativeCursor cursor) { |
| cursor_ = cursor; |
| aura::client::CursorClient* cursor_client = |
| - aura::client::GetCursorClient(window_->GetRootWindow()); |
| + aura::client::GetCursorClient(host_->window()); |
| if (cursor_client) |
| cursor_client->SetCursor(cursor); |
| } |
| -bool NativeWidgetAura::IsMouseEventsEnabled() const { |
| - if (!window_) |
| - return false; |
| +bool DesktopNativeWidgetAndroid::IsMouseEventsEnabled() const { |
| aura::client::CursorClient* cursor_client = |
| - aura::client::GetCursorClient(window_->GetRootWindow()); |
| + aura::client::GetCursorClient(host_->window()); |
| return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; |
| } |
| -void NativeWidgetAura::ClearNativeFocus() { |
| +void DesktopNativeWidgetAndroid::ClearNativeFocus() { |
| aura::client::FocusClient* client = aura::client::GetFocusClient(window_); |
| - if (window_ && client && window_->Contains(client->GetFocusedWindow())) |
| + if (client && window_->Contains(client->GetFocusedWindow())) |
| client->ResetFocusWithinActiveWindow(window_); |
| } |
| -gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
| - if (!window_) |
| - return gfx::Rect(); |
| - return gfx::Screen::GetScreenFor(window_)-> |
| - GetDisplayNearestWindow(window_).work_area(); |
| +gfx::Rect DesktopNativeWidgetAndroid::GetWorkAreaBoundsInScreen() const { |
| + return gfx::Screen::GetScreenFor(window_) |
| + ->GetDisplayNearestWindow(window_) |
| + .work_area(); |
| } |
| -Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( |
| +Widget::MoveLoopResult DesktopNativeWidgetAndroid::RunMoveLoop( |
| const gfx::Vector2d& drag_offset, |
|
mfomitchev
2015/11/11 22:40:32
Perhaps just make this NOTIMPLEMENTED()?
bshe
2015/11/12 16:19:40
Done.
|
| Widget::MoveLoopSource source, |
| Widget::MoveLoopEscapeBehavior escape_behavior) { |
| // |escape_behavior| is only needed on windows when running the native message |
| // loop. |
| - if (!window_ || !window_->GetRootWindow()) |
| - return Widget::MOVE_LOOP_CANCELED; |
| aura::client::WindowMoveClient* move_client = |
| - aura::client::GetWindowMoveClient(window_->GetRootWindow()); |
| + aura::client::GetWindowMoveClient(host_->window()); |
| if (!move_client) |
| return Widget::MOVE_LOOP_CANCELED; |
| SetCapture(); |
| aura::client::WindowMoveSource window_move_source = |
| - source == Widget::MOVE_LOOP_SOURCE_MOUSE ? |
| - aura::client::WINDOW_MOVE_SOURCE_MOUSE : |
| - aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
| + source == Widget::MOVE_LOOP_SOURCE_MOUSE |
| + ? aura::client::WINDOW_MOVE_SOURCE_MOUSE |
| + : aura::client::WINDOW_MOVE_SOURCE_TOUCH; |
| if (move_client->RunMoveLoop(window_, drag_offset, window_move_source) == |
| - aura::client::MOVE_SUCCESSFUL) { |
| + aura::client::MOVE_SUCCESSFUL) { |
| return Widget::MOVE_LOOP_SUCCESSFUL; |
| } |
| return Widget::MOVE_LOOP_CANCELED; |
| } |
| -void NativeWidgetAura::EndMoveLoop() { |
| - if (!window_ || !window_->GetRootWindow()) |
| - return; |
| +void DesktopNativeWidgetAndroid::EndMoveLoop() { |
| aura::client::WindowMoveClient* move_client = |
| - aura::client::GetWindowMoveClient(window_->GetRootWindow()); |
| + aura::client::GetWindowMoveClient(host_->window()); |
| if (move_client) |
| move_client->EndMoveLoop(); |
| } |
| -void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { |
| - if (window_) |
| - window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); |
| +void DesktopNativeWidgetAndroid::SetVisibilityChangedAnimationsEnabled( |
| + bool value) { |
| + GetNativeWindow()->SetProperty(aura::client::kAnimationsDisabledKey, !value); |
| } |
| -void NativeWidgetAura::SetVisibilityAnimationDuration( |
| +void DesktopNativeWidgetAndroid::SetVisibilityAnimationDuration( |
| const base::TimeDelta& duration) { |
| - wm::SetWindowVisibilityAnimationDuration(window_, duration); |
| + wm::SetWindowVisibilityAnimationDuration(GetNativeWindow(), duration); |
| } |
| -void NativeWidgetAura::SetVisibilityAnimationTransition( |
| +void DesktopNativeWidgetAndroid::SetVisibilityAnimationTransition( |
| Widget::VisibilityTransition transition) { |
| wm::WindowVisibilityAnimationTransition wm_transition = wm::ANIMATE_NONE; |
| switch (transition) { |
| @@ -700,25 +577,22 @@ void NativeWidgetAura::SetVisibilityAnimationTransition( |
| wm_transition = wm::ANIMATE_NONE; |
| break; |
| } |
| - wm::SetWindowVisibilityAnimationTransition(window_, wm_transition); |
| + wm::SetWindowVisibilityAnimationTransition(GetNativeWindow(), wm_transition); |
| } |
| -ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { |
| -#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| - return DesktopWindowTreeHost::GetNativeTheme(window_); |
| -#else |
| +ui::NativeTheme* DesktopNativeWidgetAndroid::GetNativeTheme() const { |
| return ui::NativeThemeAura::instance(); |
| -#endif |
| } |
| -void NativeWidgetAura::OnRootViewLayout() { |
| +void DesktopNativeWidgetAndroid::OnRootViewLayout() { |
| + NOTIMPLEMENTED(); |
| } |
| -bool NativeWidgetAura::IsTranslucentWindowOpacitySupported() const { |
| +bool DesktopNativeWidgetAndroid::IsTranslucentWindowOpacitySupported() const { |
| return true; |
| } |
| -void NativeWidgetAura::OnSizeConstraintsChanged() { |
| +void DesktopNativeWidgetAndroid::OnSizeConstraintsChanged() { |
| window_->SetProperty(aura::client::kCanMaximizeKey, |
| GetWidget()->widget_delegate()->CanMaximize()); |
| window_->SetProperty(aura::client::kCanMinimizeKey, |
| @@ -727,18 +601,19 @@ void NativeWidgetAura::OnSizeConstraintsChanged() { |
| GetWidget()->widget_delegate()->CanResize()); |
| } |
| -void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { |
| +void DesktopNativeWidgetAndroid::RepostNativeEvent( |
| + gfx::NativeEvent native_event) { |
| OnEvent(native_event); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::WindowDelegate implementation: |
| +// DesktopNativeWidgetAndroid, aura::WindowDelegate implementation: |
| -gfx::Size NativeWidgetAura::GetMinimumSize() const { |
| +gfx::Size DesktopNativeWidgetAndroid::GetMinimumSize() const { |
| return delegate_->GetMinimumSize(); |
| } |
| -gfx::Size NativeWidgetAura::GetMaximumSize() const { |
| +gfx::Size DesktopNativeWidgetAndroid::GetMaximumSize() const { |
| // If a window have a maximum size, the window should not be |
| // maximizable. |
| DCHECK(delegate_->GetMaximumSize().IsEmpty() || |
| @@ -746,8 +621,8 @@ gfx::Size NativeWidgetAura::GetMaximumSize() const { |
| return delegate_->GetMaximumSize(); |
| } |
| -void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
| - const gfx::Rect& new_bounds) { |
| +void DesktopNativeWidgetAndroid::OnBoundsChanged(const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) { |
| // Assume that if the old bounds was completely empty a move happened. This |
| // handles the case of a maximize animation acquiring the layer (acquiring a |
| // layer results in clearing the bounds). |
| @@ -759,17 +634,19 @@ void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
| delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); |
| } |
| -gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { |
| +gfx::NativeCursor DesktopNativeWidgetAndroid::GetCursor( |
| + const gfx::Point& point) { |
| return cursor_; |
| } |
| -int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { |
| +int DesktopNativeWidgetAndroid::GetNonClientComponent( |
| + const gfx::Point& point) const { |
| return delegate_->GetNonClientComponent(point); |
| } |
| -bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( |
| - aura::Window* child, |
| - const gfx::Point& location) { |
| +bool DesktopNativeWidgetAndroid::ShouldDescendIntoChildForEventHandling( |
| + aura::Window* child, |
| + const gfx::Point& location) { |
| views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); |
| if (widget_delegate && |
| !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) |
| @@ -802,64 +679,54 @@ bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( |
| return true; |
| } |
| -bool NativeWidgetAura::CanFocus() { |
| +bool DesktopNativeWidgetAndroid::CanFocus() { |
| return ShouldActivate(); |
| } |
| -void NativeWidgetAura::OnCaptureLost() { |
| +void DesktopNativeWidgetAndroid::OnCaptureLost() { |
| delegate_->OnMouseCaptureLost(); |
| } |
| -void NativeWidgetAura::OnPaint(const ui::PaintContext& context) { |
| +void DesktopNativeWidgetAndroid::OnPaint(const ui::PaintContext& context) { |
| delegate_->OnNativeWidgetPaint(context); |
| } |
| -void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| +void DesktopNativeWidgetAndroid::OnDeviceScaleFactorChanged( |
| + float device_scale_factor) { |
| GetWidget()->DeviceScaleFactorChanged(device_scale_factor); |
| } |
| -void NativeWidgetAura::OnWindowDestroying(aura::Window* window) { |
| - window_->RemoveObserver(this); |
| +void DesktopNativeWidgetAndroid::OnWindowDestroying(aura::Window* window) { |
| delegate_->OnNativeWidgetDestroying(); |
| // If the aura::Window is destroyed, we can no longer show tooltips. |
| tooltip_manager_.reset(); |
| } |
| -void NativeWidgetAura::OnWindowDestroyed(aura::Window* window) { |
| +void DesktopNativeWidgetAndroid::OnWindowDestroyed(aura::Window* window) { |
| window_ = NULL; |
| delegate_->OnNativeWidgetDestroyed(); |
| if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| delete this; |
| } |
| -void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { |
| +void DesktopNativeWidgetAndroid::OnWindowTargetVisibilityChanged(bool visible) { |
| delegate_->OnNativeWidgetVisibilityChanged(visible); |
| } |
| -bool NativeWidgetAura::HasHitTestMask() const { |
| +bool DesktopNativeWidgetAndroid::HasHitTestMask() const { |
| return delegate_->HasHitTestMask(); |
| } |
| -void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { |
| +void DesktopNativeWidgetAndroid::GetHitTestMask(gfx::Path* mask) const { |
| DCHECK(mask); |
| delegate_->GetHitTestMask(mask); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::WindowObserver implementation: |
| - |
| -void NativeWidgetAura::OnWindowPropertyChanged(aura::Window* window, |
| - const void* key, |
| - intptr_t old) { |
| - if (key == aura::client::kShowStateKey) |
| - delegate_->OnNativeWidgetWindowShowStateChanged(); |
| -} |
| - |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, ui::EventHandler implementation: |
| +// DesktopNativeWidgetAndroid, ui::EventHandler implementation: |
| -void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { |
| +void DesktopNativeWidgetAndroid::OnKeyEvent(ui::KeyEvent* event) { |
| DCHECK(window_); |
| // Renderer may send a key event back to us if the key event wasn't handled, |
| // and the window may be invisible by that time. |
| @@ -873,7 +740,7 @@ void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { |
| event->SetHandled(); |
| } |
| -void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { |
| +void DesktopNativeWidgetAndroid::OnMouseEvent(ui::MouseEvent* event) { |
| DCHECK(window_); |
| DCHECK(window_->IsVisible()); |
| if (event->type() == ui::ET_MOUSEWHEEL) { |
| @@ -888,27 +755,28 @@ void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { |
| delegate_->OnMouseEvent(event); |
| } |
| -void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { |
| +void DesktopNativeWidgetAndroid::OnScrollEvent(ui::ScrollEvent* event) { |
| delegate_->OnScrollEvent(event); |
| } |
| -void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { |
| +void DesktopNativeWidgetAndroid::OnGestureEvent(ui::GestureEvent* event) { |
| DCHECK(window_); |
| DCHECK(window_->IsVisible() || event->IsEndingEvent()); |
| delegate_->OnGestureEvent(event); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::client::ActivationDelegate implementation: |
| +// DesktopNativeWidgetAndroid, aura::client::ActivationDelegate implementation: |
| -bool NativeWidgetAura::ShouldActivate() const { |
| +bool DesktopNativeWidgetAndroid::ShouldActivate() const { |
| return delegate_->CanActivate(); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::client::ActivationChangeObserver implementation: |
| +// DesktopNativeWidgetAndroid, aura::client::ActivationChangeObserver |
| +// implementation: |
| -void NativeWidgetAura::OnWindowActivated( |
| +void DesktopNativeWidgetAndroid::OnWindowActivated( |
| aura::client::ActivationChangeObserver::ActivationReason, |
| aura::Window* gained_active, |
| aura::Window* lost_active) { |
| @@ -923,10 +791,10 @@ void NativeWidgetAura::OnWindowActivated( |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::client::FocusChangeObserver: |
| +// DesktopNativeWidgetAndroid, aura::client::FocusChangeObserver: |
| -void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, |
| - aura::Window* lost_focus) { |
| +void DesktopNativeWidgetAndroid::OnWindowFocused(aura::Window* gained_focus, |
| + aura::Window* lost_focus) { |
| if (window_ == gained_focus) |
| delegate_->OnNativeFocus(); |
| else if (window_ == lost_focus) |
| @@ -934,239 +802,80 @@ void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, aura::WindowDragDropDelegate implementation: |
| - |
| -void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { |
| - DCHECK(drop_helper_.get() != NULL); |
| - last_drop_operation_ = drop_helper_->OnDragOver(event.data(), |
| - event.location(), event.source_operations()); |
| -} |
| +// DesktopNativeWidgetAndroid, aura::WindowDragDropDelegate implementation: |
| -int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { |
| - DCHECK(drop_helper_.get() != NULL); |
| - last_drop_operation_ = drop_helper_->OnDragOver(event.data(), |
| - event.location(), event.source_operations()); |
| - return last_drop_operation_; |
| +void DesktopNativeWidgetAndroid::OnDragEntered( |
| + const ui::DropTargetEvent& event) { |
| + // TODO: Implement drag and drop. crbug.com/554029. |
| + NOTIMPLEMENTED(); |
| } |
| -void NativeWidgetAura::OnDragExited() { |
| - DCHECK(drop_helper_.get() != NULL); |
| - drop_helper_->OnDragExit(); |
| +int DesktopNativeWidgetAndroid::OnDragUpdated( |
| + const ui::DropTargetEvent& event) { |
| + // TODO: Implement drag and drop. crbug.com/554029. |
| + NOTIMPLEMENTED(); |
| + return 0; |
| } |
| -int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { |
| - DCHECK(drop_helper_.get() != NULL); |
| - return drop_helper_->OnDrop(event.data(), event.location(), |
| - last_drop_operation_); |
| +void DesktopNativeWidgetAndroid::OnDragExited() { |
| + // TODO: Implement drag and drop. crbug.com/554029. |
| + NOTIMPLEMENTED(); |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, protected: |
| - |
| -NativeWidgetAura::~NativeWidgetAura() { |
| - destroying_ = true; |
| - if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| - delete delegate_; |
| - else |
| - CloseNow(); |
| +int DesktopNativeWidgetAndroid::OnPerformDrop( |
| + const ui::DropTargetEvent& event) { |
| + // TODO: Implement drag and drop. crbug.com/554029. |
| + NOTIMPLEMENTED(); |
| + return 0; |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// NativeWidgetAura, private: |
| +// DesktopNativeWidgetAndroid, aura::WindowTreeHostObserver implementation: |
| -bool NativeWidgetAura::IsDocked() const { |
| - return window_ && |
| - window_->GetProperty(aura::client::kShowStateKey) == |
| - ui::SHOW_STATE_DOCKED; |
| +void DesktopNativeWidgetAndroid::OnHostCloseRequested( |
| + const aura::WindowTreeHost* host) { |
| + GetWidget()->Close(); |
| } |
| -void NativeWidgetAura::SetInitialFocus(ui::WindowShowState show_state) { |
| - // The window does not get keyboard messages unless we focus it. |
| - if (!GetWidget()->SetInitialFocus(show_state)) |
| - window_->Focus(); |
| +void DesktopNativeWidgetAndroid::OnHostResized( |
| + const aura::WindowTreeHost* host) { |
| + gfx::Rect new_bounds = gfx::Rect(host_->window()->bounds().size()); |
| + GetNativeWindow()->SetBounds(new_bounds); |
| + delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); |
| } |
| -//////////////////////////////////////////////////////////////////////////////// |
| -// Widget, public: |
| - |
| -namespace { |
| -#if defined(OS_WIN) || (defined(USE_X11) && !defined(OS_CHROMEOS)) |
| -void CloseWindow(aura::Window* window) { |
| - if (window) { |
| - Widget* widget = Widget::GetWidgetForNativeView(window); |
| - if (widget && widget->is_secondary_widget()) |
| - // To avoid the delay in shutdown caused by using Close which may wait |
| - // for animations, use CloseNow. Because this is only used on secondary |
| - // widgets it seems relatively safe to skip the extra processing of |
| - // Close. |
| - widget->CloseNow(); |
| - } |
| -} |
| -#endif |
| +void DesktopNativeWidgetAndroid::OnHostMoved(const aura::WindowTreeHost* host, |
| + const gfx::Point& new_origin) { |
| + TRACE_EVENT1("views", "DesktopNativeWidgetAndroid::OnHostMoved", "new_origin", |
| + new_origin.ToString()); |
| -#if defined(OS_WIN) |
| -BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) { |
| - aura::Window* root_window = |
| - DesktopWindowTreeHostWin::GetContentWindowForHWND(hwnd); |
| - CloseWindow(root_window); |
| - return TRUE; |
| + delegate_->OnNativeWidgetMove(); |
| } |
| -#endif |
| -} // namespace |
| - |
| -// static |
| -void Widget::CloseAllSecondaryWidgets() { |
| -#if defined(OS_WIN) |
| - EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); |
| -#endif |
| - |
| -#if defined(USE_X11) && !defined(OS_CHROMEOS) |
| - DesktopWindowTreeHostX11::CleanUpWindowList(CloseWindow); |
| -#endif |
| -} |
| - |
| -bool Widget::ConvertRect(const Widget* source, |
| - const Widget* target, |
| - gfx::Rect* rect) { |
| - return false; |
| -} |
| - |
| -namespace internal { |
| //////////////////////////////////////////////////////////////////////////////// |
| -// internal::NativeWidgetPrivate, public: |
| - |
| -// static |
| -NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( |
| - internal::NativeWidgetDelegate* delegate) { |
| - return new NativeWidgetAura(delegate); |
| -} |
| - |
| -// static |
| -NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( |
| - gfx::NativeView native_view) { |
| - // Cast must match type supplied to RegisterNativeWidgetForWindow(). |
| - return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data()); |
| -} |
| - |
| -// static |
| -NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( |
| - gfx::NativeWindow native_window) { |
| - // Cast must match type supplied to RegisterNativeWidgetForWindow(). |
| - return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data()); |
| -} |
| - |
| -// static |
| -NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( |
| - gfx::NativeView native_view) { |
| - aura::Window* window = native_view; |
| - NativeWidgetPrivate* top_level_native_widget = NULL; |
| - while (window) { |
| - NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); |
| - if (native_widget) |
| - top_level_native_widget = native_widget; |
| - window = window->parent(); |
| - } |
| - return top_level_native_widget; |
| -} |
| - |
| -// static |
| -void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, |
| - Widget::Widgets* children) { |
| - { |
| - // Code expects widget for |native_view| to be added to |children|. |
| - NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( |
| - GetNativeWidgetForNativeView(native_view)); |
| - if (native_widget && native_widget->GetWidget()) |
| - children->insert(native_widget->GetWidget()); |
| - } |
| +// DesktopNativeWidgetAndroid, protected: |
| - const aura::Window::Windows& child_windows = native_view->children(); |
| - for (aura::Window::Windows::const_iterator i = child_windows.begin(); |
| - i != child_windows.end(); ++i) { |
| - GetAllChildWidgets((*i), children); |
| - } |
| -} |
| - |
| -// static |
| -void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, |
| - Widget::Widgets* owned) { |
| - // Add all owned widgets. |
| - for (aura::Window* transient_child : wm::GetTransientChildren(native_view)) { |
| - NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>( |
| - GetNativeWidgetForNativeView(transient_child)); |
| - if (native_widget && native_widget->GetWidget()) |
| - owned->insert(native_widget->GetWidget()); |
| - GetAllOwnedWidgets(transient_child, owned); |
| - } |
| - |
| - // Add all child windows. |
| - for (aura::Window* child : native_view->children()) |
| - GetAllChildWidgets(child, owned); |
| +DesktopNativeWidgetAndroid::~DesktopNativeWidgetAndroid() { |
| + destroying_ = true; |
| + if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| + delete delegate_; |
| + else |
| + CloseNow(); |
| } |
| -// static |
| -void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, |
| - gfx::NativeView new_parent) { |
| - DCHECK(native_view != new_parent); |
| - |
| - gfx::NativeView previous_parent = native_view->parent(); |
| - if (previous_parent == new_parent) |
| - return; |
| - |
| - Widget::Widgets widgets; |
| - GetAllChildWidgets(native_view, &widgets); |
| - |
| - // First notify all the widgets that they are being disassociated |
| - // from their previous parent. |
| - for (Widget::Widgets::iterator it = widgets.begin(); |
| - it != widgets.end(); ++it) { |
| - (*it)->NotifyNativeViewHierarchyWillChange(); |
| - } |
| - |
| - if (new_parent) { |
| - new_parent->AddChild(native_view); |
| - } else { |
| - // The following looks weird, but it's the equivalent of what aura has |
| - // always done. (The previous behaviour of aura::Window::SetParent() used |
| - // NULL as a special value that meant ask the WindowTreeClient where things |
| - // should go.) |
| - // |
| - // This probably isn't strictly correct, but its an invariant that a Window |
| - // in use will be attached to a RootWindow, so we can't just call |
| - // RemoveChild here. The only possible thing that could assign a RootWindow |
| - // in this case is the stacking client of the current RootWindow. This |
| - // matches our previous behaviour; the global stacking client would almost |
| - // always reattach the window to the same RootWindow. |
| - aura::Window* root_window = native_view->GetRootWindow(); |
| - aura::client::ParentWindowWithContext( |
| - native_view, root_window, root_window->GetBoundsInScreen()); |
| - } |
| - |
| - // And now, notify them that they have a brand new parent. |
| - for (Widget::Widgets::iterator it = widgets.begin(); |
| - it != widgets.end(); ++it) { |
| - (*it)->NotifyNativeViewHierarchyChanged(); |
| - } |
| -} |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// DesktopNativeWidgetAndroid, private: |
| -// static |
| -bool NativeWidgetPrivate::IsMouseButtonDown() { |
| - return aura::Env::GetInstance()->IsMouseButtonDown(); |
| +bool DesktopNativeWidgetAndroid::IsDocked() const { |
| + NOTIMPLEMENTED(); |
| + return false; |
| } |
| -// static |
| -gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { |
| -#if defined(OS_WIN) |
| - NONCLIENTMETRICS_XP ncm; |
| - base::win::GetNonClientMetrics(&ncm); |
| - l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
| - base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
| - return gfx::FontList(gfx::Font(caption_font)); |
| -#else |
| - return gfx::FontList(); |
| -#endif |
| +void DesktopNativeWidgetAndroid::SetInitialFocus( |
| + ui::WindowShowState show_state) { |
| + // The window does not get keyboard messages unless we focus it. |
| + if (!GetWidget()->SetInitialFocus(show_state)) |
| + window_->Focus(); |
| } |
| -} // namespace internal |
| } // namespace views |