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)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/win/metro.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkPath.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkRegion.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
11b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ui/aura/client/cursor_client.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ui/aura/client/focus_client.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_property.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/cursor/cursor_loader_win.h"
167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/ime/input_method.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/win/shell.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/compositor/compositor_constants.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/insets.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/native_widget_types.h"
21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/path.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/path_win.h"
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/vector2d.h"
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/win/dpi.h"
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/native_theme/native_theme_aura.h"
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/native_theme/native_theme_win.h"
274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/corewm/tooltip_win.h"
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/ime/input_method_bridge.h"
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/root_view.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_delegate.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_hwnd_utils.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/win/fullscreen_handler.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/win/hwnd_message_handler.h"
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/compound_event_filter.h"
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/input_method_event_filter.h"
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_animations.h"
41effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/scoped_tooltip_disabler.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace views {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace {
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)gfx::Size GetExpandedWindowSize(DWORD window_style, gfx::Size size) {
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!(window_style & WS_EX_COMPOSITED) || !ui::win::IsAeroGlassEnabled())
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return size;
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Some AMD drivers can't display windows that are less than 64x64 pixels,
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // so expand them to be at least that size. http://crbug.com/286609
53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Size expanded(std::max(size.width(), 64), std::max(size.height(), 64));
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return expanded;
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void InsetBottomRight(gfx::Rect* rect, gfx::Vector2d vector) {
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  rect->Inset(0, 0, vector.x(), vector.y());
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace
62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL);
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Identifies the DesktopWindowTreeHostWin associated with the
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// WindowEventDispatcher.
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DEFINE_WINDOW_PROPERTY_KEY(DesktopWindowTreeHostWin*, kDesktopWindowTreeHostKey,
680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                           NULL);
690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, public:
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::is_cursor_visible_ = true;
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DesktopWindowTreeHostWin::DesktopWindowTreeHostWin(
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    internal::NativeWidgetDelegate* native_widget_delegate,
771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DesktopNativeWidgetAura* desktop_native_widget_aura)
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : message_handler_(new HWNDMessageHandler(this)),
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      native_widget_delegate_(native_widget_delegate),
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      desktop_native_widget_aura_(desktop_native_widget_aura),
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      content_window_(NULL),
821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      drag_drop_client_(NULL),
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      should_animate_window_close_(false),
84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      pending_close_(false),
854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      has_non_client_view_(false),
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      tooltip_(NULL),
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      need_synchronous_paint_(false),
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      in_sizing_loop_(false) {
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DesktopWindowTreeHostWin::~DesktopWindowTreeHostWin() {
928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // WARNING: |content_window_| has been destroyed by the time we get here.
93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  desktop_native_widget_aura_->OnDesktopWindowTreeHostDestroyed(this);
94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DestroyDispatcher();
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)aura::Window* DesktopWindowTreeHostWin::GetContentWindowForHWND(HWND hwnd) {
99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  aura::WindowTreeHost* host =
100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      aura::WindowTreeHost::GetForAcceleratedWidget(hwnd);
101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return host ? host->window()->GetProperty(kContentWindowForRootWindow) : NULL;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ui::NativeTheme* DesktopWindowTreeHost::GetNativeTheme(aura::Window* window) {
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use NativeThemeWin for windows shown on the desktop, those not on the
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // desktop come from Ash and get NativeThemeAura.
108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  aura::WindowTreeHost* host = window ? window->GetHost() : NULL;
109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (host) {
110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    HWND host_hwnd = host->GetAcceleratedWidget();
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (host_hwnd &&
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        DesktopWindowTreeHostWin::GetContentWindowForHWND(host_hwnd)) {
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return ui::NativeThemeWin::instance();
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return ui::NativeThemeAura::instance();
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, DesktopWindowTreeHost implementation:
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void DesktopWindowTreeHostWin::Init(aura::Window* content_window,
123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                    const Widget::InitParams& params) {
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): SetInitParams().
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content_window_ = content_window;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::client::SetAnimationHost(content_window_, this);
1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ConfigureWindowStyles(message_handler_.get(), params,
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        GetWidget()->widget_delegate(),
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        native_widget_delegate_);
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  HWND parent_hwnd = NULL;
134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (params.parent && params.parent->GetHost())
135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget();
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  message_handler_->set_remove_standard_frame(params.remove_standard_frame);
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  has_non_client_view_ = Widget::RequiresNonClientView(params.type);
140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
14158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(params.bounds);
142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  message_handler_->Init(parent_hwnd, pixel_bounds);
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (params.type == Widget::InitParams::TYPE_MENU) {
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ::SetProp(GetAcceleratedWidget(),
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              kForceSoftwareCompositor,
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              reinterpret_cast<HANDLE>(true));
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CreateCompositor(GetAcceleratedWidget());
1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void DesktopWindowTreeHostWin::OnNativeWidgetCreated(
1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const Widget::InitParams& params) {
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The cursor is not necessarily visible when the root window is created.
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::client::CursorClient* cursor_client =
155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      aura::client::GetCursorClient(window());
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (cursor_client)
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    is_cursor_visible_ = cursor_client->IsCursorVisible();
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
159a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window()->SetProperty(kContentWindowForRootWindow, content_window_);
160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window()->SetProperty(kDesktopWindowTreeHostKey, this);
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  should_animate_window_close_ =
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      content_window_->type() != ui::wm::WINDOW_TYPE_NORMAL &&
164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      !wm::WindowAnimationsDisabled(content_window_);
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// TODO this is not invoked *after* Init(), but should be ok.
1670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SetWindowTransparency();
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)scoped_ptr<corewm::Tooltip> DesktopWindowTreeHostWin::CreateTooltip() {
1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DCHECK(!tooltip_);
1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  tooltip_ = new corewm::TooltipWin(GetAcceleratedWidget());
1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return scoped_ptr<corewm::Tooltip>(tooltip_);
1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)scoped_ptr<aura::client::DragDropClient>
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DesktopWindowTreeHostWin::CreateDragDropClient(
1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DesktopNativeCursorManager* cursor_manager) {
179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  drag_drop_client_ = new DesktopDragDropClientWin(window(), GetHWND());
1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return scoped_ptr<aura::client::DragDropClient>(drag_drop_client_).Pass();
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Close() {
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // TODO(beng): Move this entire branch to DNWA so it can be shared with X11.
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (should_animate_window_close_) {
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    pending_close_ = true;
187a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    const bool is_animating =
188a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        content_window_->layer()->GetAnimator()->IsAnimatingProperty(
189a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)            ui::LayerAnimationElement::VISIBILITY);
190a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // Animation may not start for a number of reasons.
191a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    if (!is_animating)
192a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      message_handler_->Close();
193a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    // else case, OnWindowHidingAnimationCompleted does the actual Close.
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  } else {
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    message_handler_->Close();
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::CloseNow() {
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->CloseNow();
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)aura::WindowTreeHost* DesktopWindowTreeHostWin::AsWindowTreeHost() {
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return this;
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::ShowWindowWithState(
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::WindowShowState show_state) {
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->ShowWindowWithState(show_state);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::ShowMaximizedWithBounds(
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Rect& restored_bounds) {
21458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(restored_bounds);
215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  message_handler_->ShowMaximizedWithBounds(pixel_bounds);
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsVisible() const {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->IsVisible();
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetSize(const gfx::Size& size) {
22358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Size size_in_pixels = gfx::win::DIPToScreenSize(size);
224f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Size expanded = GetExpandedWindowSize(
225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      message_handler_->window_ex_style(), size_in_pixels);
226f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  window_enlargement_ =
227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      gfx::Vector2d(expanded.width() - size_in_pixels.width(),
228f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    expanded.height() - size_in_pixels.height());
229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  message_handler_->SetSize(expanded);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::StackAtTop() {
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  message_handler_->StackAtTop();
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::CenterWindow(const gfx::Size& size) {
23758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Size size_in_pixels = gfx::win::DIPToScreenSize(size);
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Size expanded_size;
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  expanded_size = GetExpandedWindowSize(message_handler_->window_ex_style(),
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                        size_in_pixels);
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window_enlargement_ =
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Vector2d(expanded_size.width() - size_in_pixels.width(),
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    expanded_size.height() - size_in_pixels.height());
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  message_handler_->CenterWindow(expanded_size);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::GetWindowPlacement(
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Rect* bounds,
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::WindowShowState* show_state) const {
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->GetWindowPlacement(bounds, show_state);
251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  InsetBottomRight(bounds, window_enlargement_);
25258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  *bounds = gfx::win::ScreenToDIPRect(*bounds);
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Rect DesktopWindowTreeHostWin::GetWindowBoundsInScreen() const {
256c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen();
257f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  InsetBottomRight(&pixel_bounds, window_enlargement_);
25858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return gfx::win::ScreenToDIPRect(pixel_bounds);
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Rect DesktopWindowTreeHostWin::GetClientAreaBoundsInScreen() const {
262c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Rect pixel_bounds = message_handler_->GetClientAreaBoundsInScreen();
263f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  InsetBottomRight(&pixel_bounds, window_enlargement_);
26458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return gfx::win::ScreenToDIPRect(pixel_bounds);
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Rect DesktopWindowTreeHostWin::GetRestoredBounds() const {
268c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Rect pixel_bounds = message_handler_->GetRestoredBounds();
269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  InsetBottomRight(&pixel_bounds, window_enlargement_);
27058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return gfx::win::ScreenToDIPRect(pixel_bounds);
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const {
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MONITORINFO monitor_info;
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  monitor_info.cbSize = sizeof(monitor_info);
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(),
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   MONITOR_DEFAULTTONEAREST),
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 &monitor_info);
279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork);
28058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  return gfx::win::ScreenToDIPRect(pixel_bounds);
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetShape(gfx::NativeRegion native_region) {
284f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (native_region) {
2851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // TODO(wez): This would be a lot simpler if we were passed an SkPath.
2861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // See crbug.com/410593.
2871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    gfx::NativeRegion shape = native_region;
2881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    SkRegion device_region;
2891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (gfx::IsInHighDPIMode()) {
2901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      shape = &device_region;
2911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const float& scale = gfx::GetDPIScale();
2921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      std::vector<SkIRect> rects;
2931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      for (SkRegion::Iterator it(*native_region); !it.done(); it.next()) {
2941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        const SkIRect& rect = it.rect();
2951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        SkRect scaled_rect =
2961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci            SkRect::MakeLTRB(rect.left() * scale, rect.top() * scale,
2971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                             rect.right() * scale, rect.bottom() * scale);
2981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        SkIRect rounded_scaled_rect;
2991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        scaled_rect.roundOut(&rounded_scaled_rect);
3001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        rects.push_back(rounded_scaled_rect);
3011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      }
3021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      if (!rects.empty())
3031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci        device_region.setRects(&rects[0], rects.size());
3041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    }
3051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    message_handler_->SetRegion(gfx::CreateHRGNFromSkRegion(*shape));
307f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else {
308f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    message_handler_->SetRegion(NULL);
309f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
310f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
311f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  delete native_region;
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Activate() {
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Activate();
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Deactivate() {
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Deactivate();
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsActive() const {
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->IsActive();
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Maximize() {
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Maximize();
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Minimize() {
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Minimize();
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Restore() {
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Restore();
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsMaximized() const {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->IsMaximized();
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsMinimized() const {
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->IsMinimized();
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HasCapture() const {
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->HasCapture();
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetAlwaysOnTop(bool always_on_top) {
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->SetAlwaysOnTop(always_on_top);
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsAlwaysOnTop() const {
3554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return message_handler_->IsAlwaysOnTop();
3564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
3574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
358a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void DesktopWindowTreeHostWin::SetVisibleOnAllWorkspaces(bool always_visible) {
359a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Windows does not have the concept of workspaces.
360a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
361a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::SetWindowTitle(const base::string16& title) {
363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return message_handler_->SetTitle(title);
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::ClearNativeFocus() {
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->ClearNativeFocus();
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Widget::MoveLoopResult DesktopWindowTreeHostWin::RunMoveLoop(
3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const gfx::Vector2d& drag_offset,
37268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    Widget::MoveLoopSource source,
37368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    Widget::MoveLoopEscapeBehavior escape_behavior) {
37468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const bool hide_on_escape =
37568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      escape_behavior == Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE;
37668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  return message_handler_->RunMoveLoop(drag_offset, hide_on_escape) ?
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED;
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::EndMoveLoop() {
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->EndMoveLoop();
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetVisibilityChangedAnimationsEnabled(
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool value) {
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->SetVisibilityChangedAnimationsEnabled(value);
387c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content_window_->SetProperty(aura::client::kAnimationsDisabledKey, !value);
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::ShouldUseNativeFrame() const {
391116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return IsTranslucentWindowOpacitySupported();
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::ShouldWindowContentsBeTransparent() const {
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If the window has a native frame, we assume it is an Aero Glass window, and
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is therefore transparent. Note: This is not equivalent to calling
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // IsAeroGlassEnabled, because ShouldUseNativeFrame is overridden in a
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // subclass.
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ShouldUseNativeFrame();
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::FrameTypeChanged() {
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->FrameTypeChanged();
4040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SetWindowTransparency();
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetFullscreen(bool fullscreen) {
40803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  message_handler_->SetFullscreen(fullscreen);
409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // TODO(sky): workaround for ScopedFullscreenVisibility showing window
410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // directly. Instead of this should listen for visibility changes and then
411a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // update window.
412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (message_handler_->IsVisible() && !content_window_->TargetVisibility())
413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    content_window_->Show();
4140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  SetWindowTransparency();
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsFullscreen() const {
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->fullscreen_handler()->fullscreen();
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetOpacity(unsigned char opacity) {
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->SetOpacity(static_cast<BYTE>(opacity));
423c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  content_window_->layer()->SetOpacity(opacity / 255.0);
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetWindowIcons(
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) {
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->SetWindowIcons(window_icon, app_icon);
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::InitModalType(ui::ModalType modal_type) {
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->InitModalType(modal_type);
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::FlashFrame(bool flash_frame) {
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->FlashFrame(flash_frame);
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
439116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid DesktopWindowTreeHostWin::OnRootViewLayout() {
44058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
44158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::OnNativeWidgetFocus() {
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HWNDMessageHandler will perform the proper updating on its own.
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::OnNativeWidgetBlur() {
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsAnimatingClosed() const {
4501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  return pending_close_;
4511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
4521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
453116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbool DesktopWindowTreeHostWin::IsTranslucentWindowOpacitySupported() const {
454116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return ui::win::IsAeroGlassEnabled();
455116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
456116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid DesktopWindowTreeHostWin::SizeConstraintsChanged() {
4581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  message_handler_->SizeConstraintsChanged();
4591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
4601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, WindowTreeHost implementation:
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4645c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuui::EventSource* DesktopWindowTreeHostWin::GetEventSource() {
4655c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  return this;
4665c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
4675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::AcceleratedWidget DesktopWindowTreeHostWin::GetAcceleratedWidget() {
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->hwnd();
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Show() {
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->Show();
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::Hide() {
4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!pending_close_)
4782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    message_handler_->Hide();
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
481c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// GetBounds and SetBounds work in pixel coordinates, whereas other get/set
482c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// methods work in DIP.
483c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Rect DesktopWindowTreeHostWin::GetBounds() const {
4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect bounds(message_handler_->GetClientAreaBounds());
4864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If the window bounds were expanded we need to return the original bounds
4874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // To achieve this we do the reverse of the expansion, i.e. add the
4884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // window_expansion_top_left_delta_ to the origin and subtract the
4894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // window_expansion_bottom_right_delta_ from the width and height.
4904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect without_expansion(
4914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.x() + window_expansion_top_left_delta_.x(),
4924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.y() + window_expansion_top_left_delta_.y(),
493f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      bounds.width() - window_expansion_bottom_right_delta_.x() -
494f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          window_enlargement_.x(),
495f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      bounds.height() - window_expansion_bottom_right_delta_.y() -
496f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)          window_enlargement_.y());
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return without_expansion;
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
5014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If the window bounds have to be expanded we need to subtract the
5024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // window_expansion_top_left_delta_ from the origin and add the
5034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // window_expansion_bottom_right_delta_ to the width and height
5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Size old_hwnd_size(message_handler_->GetClientAreaBounds().size());
5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Size old_content_size = GetBounds().size();
5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect expanded(
5084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.x() - window_expansion_top_left_delta_.x(),
5094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.y() - window_expansion_top_left_delta_.y(),
5104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.width() + window_expansion_bottom_right_delta_.x(),
5114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      bounds.height() + window_expansion_bottom_right_delta_.y());
512f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
513f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect new_expanded(
514f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      expanded.origin(),
515f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetExpandedWindowSize(message_handler_->window_ex_style(),
516f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                            expanded.size()));
517f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  window_enlargement_ =
518f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      gfx::Vector2d(new_expanded.width() - expanded.width(),
519f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                    new_expanded.height() - expanded.height());
520cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  message_handler_->SetBounds(new_expanded, old_content_size != bounds.size());
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Point DesktopWindowTreeHostWin::GetLocationOnNativeScreen() const {
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return GetBounds().origin();
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetCapture() {
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->SetCapture();
5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::ReleaseCapture() {
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  message_handler_->ReleaseCapture();
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::PostNativeEvent(
5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::NativeEvent& native_event) {
5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetCursorNative(gfx::NativeCursor cursor) {
5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::CursorLoaderWin cursor_loader;
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  cursor_loader.SetPlatformCursor(&cursor);
5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  message_handler_->SetCursor(cursor.platform());
5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (is_cursor_visible_ == show)
548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
549f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  is_cursor_visible_ = show;
5500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  ::ShowCursor(!!show);
5512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
554b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  POINT cursor_location = location.ToPOINT();
555b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ::ClientToScreen(GetHWND(), &cursor_location);
556b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  ::SetCursorPos(cursor_location.x, cursor_location.y);
5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, ui::EventSource implementation:
5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ui::EventProcessor* DesktopWindowTreeHostWin::GetEventProcessor() {
563a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return dispatcher();
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, aura::AnimationHost implementation:
5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetHostTransitionOffsets(
5704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const gfx::Vector2d& top_left_delta,
5714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    const gfx::Vector2d& bottom_right_delta) {
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Rect bounds_without_expansion = GetBounds();
5734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_expansion_top_left_delta_ = top_left_delta;
5744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_expansion_bottom_right_delta_ = bottom_right_delta;
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SetBounds(bounds_without_expansion);
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::OnWindowHidingAnimationCompleted() {
5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (pending_close_)
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    message_handler_->Close();
5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, HWNDMessageHandlerDelegate implementation:
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsWidgetWindow() const {
587c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return has_non_client_view_;
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsUsingCustomFrame() const {
5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return !GetWidget()->ShouldUseNativeFrame();
5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SchedulePaint() {
5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->GetRootView()->SchedulePaint();
5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::EnableInactiveRendering() {
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->EnableInactiveRendering();
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsInactiveRenderingDisabled() {
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->IsInactiveRenderingDisabled();
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::CanResize() const {
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->widget_delegate()->CanResize();
6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::CanMaximize() const {
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->widget_delegate()->CanMaximize();
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool DesktopWindowTreeHostWin::CanMinimize() const {
6151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return GetWidget()->widget_delegate()->CanMinimize();
6161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
6171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::CanActivate() const {
6194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (IsModalWindowActive())
6204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return true;
6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->CanActivate();
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::WidgetSizeIsClientSize() const {
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const Widget* widget = GetWidget()->GetTopLevelWidget();
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return IsMaximized() || (widget && widget->ShouldUseNativeFrame());
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsModal() const {
6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->IsModal();
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int DesktopWindowTreeHostWin::GetInitialShowState() const {
634cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return CanActivate() ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE;
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::WillProcessWorkAreaChange() const {
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->widget_delegate()->WillProcessWorkAreaChange();
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int DesktopWindowTreeHostWin::GetNonClientComponent(
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Point& point) const {
64358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Point dip_position = gfx::win::ScreenToDIPPoint(point);
64490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return native_widget_delegate_->GetNonClientComponent(dip_position);
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::GetWindowMask(const gfx::Size& size,
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             gfx::Path* path) {
649f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (GetWidget()->non_client_view()) {
6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GetWidget()->non_client_view()->GetWindowMask(size, path);
651f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  } else if (!window_enlargement_.IsZero()) {
652f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    gfx::Rect bounds(WidgetSizeIsClientSize()
653f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                         ? message_handler_->GetClientAreaBoundsInScreen()
654f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                         : message_handler_->GetWindowBoundsInScreen());
655f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    InsetBottomRight(&bounds, window_enlargement_);
656f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    path->addRect(SkRect::MakeXYWH(0, 0, bounds.width(), bounds.height()));
657f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::GetClientAreaInsets(gfx::Insets* insets) const {
6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::GetMinMaxSize(gfx::Size* min_size,
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             gfx::Size* max_size) const {
6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *min_size = native_widget_delegate_->GetMinimumSize();
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  *max_size = native_widget_delegate_->GetMaximumSize();
6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::Size DesktopWindowTreeHostWin::GetRootViewSize() const {
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->GetRootView()->size();
6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::ResetWindowControls() {
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->non_client_view()->ResetWindowControls();
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::PaintLayeredWindow(gfx::Canvas* canvas) {
679cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  GetWidget()->GetRootView()->Paint(canvas, views::CullSet());
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeViewAccessible DesktopWindowTreeHostWin::GetNativeViewAccessible() {
6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->GetRootView()->GetNativeViewAccessible();
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)InputMethod* DesktopWindowTreeHostWin::GetInputMethod() {
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->GetInputMethodDirect();
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::ShouldHandleSystemCommands() const {
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return GetWidget()->widget_delegate()->ShouldHandleSystemCommands();
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleAppDeactivated() {
6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->EnableInactiveRendering();
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleActivationChanged(bool active) {
6994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // This can be invoked from HWNDMessageHandler::Init(), at which point we're
7004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // not in a good state and need to ignore it.
701a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // TODO(beng): Do we need this still now the host owns the dispatcher?
702a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!dispatcher())
7034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
7044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (active)
706a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    OnHostActivated();
70758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  desktop_native_widget_aura_->HandleActivationChanged(active);
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleAppCommand(short command) {
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We treat APPCOMMAND ids as an extension of our command namespace, and just
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // let the delegate figure out what to do...
7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->widget_delegate() &&
7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleCancelMode() {
718a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  dispatcher()->DispatchCancelModeEvent();
7192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleCaptureLost() {
722a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  OnHostLostWindowCapture();
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleClose() {
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->Close();
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleCommand(int command) {
7301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Windows uses the 4 lower order bits of |notification_code| for type-
7311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // specific information so we must exclude this when comparing.
7321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static const int sc_mask = 0xFFF0;
7331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  switch (command & sc_mask) {
7341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    case SC_RESTORE:
7351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    case SC_MAXIMIZE:
7361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      need_synchronous_paint_ = true;
7371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      break;
7381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    case SC_SIZE:
7401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      in_sizing_loop_ = true;
7411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      break;
7421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    default:
7441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      break;
7451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleAccelerator(
7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::Accelerator& accelerator) {
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator);
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleCreate() {
755f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  native_widget_delegate_->OnNativeWidgetCreated(true);
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleDestroying() {
7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  drag_drop_client_->OnNativeWidgetDestroying(GetHWND());
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetDestroying();
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Destroy the compositor before destroying the HWND since shutdown
7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // may try to swap to the window.
7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DestroyCompositor();
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleDestroyed() {
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  desktop_native_widget_aura_->OnHostClosed();
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleInitialFocus(
7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ui::WindowShowState show_state) {
7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return GetWidget()->SetInitialFocus(show_state);
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleDisplayChange() {
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->widget_delegate()->OnDisplayChanged();
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleBeginWMSizeMove() {
7811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (in_sizing_loop_)
7821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    need_synchronous_paint_ = true;
7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetBeginUserBoundsChange();
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleEndWMSizeMove() {
7871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (in_sizing_loop_) {
7881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    need_synchronous_paint_ = false;
7891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    in_sizing_loop_ = false;
7901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetEndUserBoundsChange();
7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleMove() {
7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetMove();
796a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  OnHostMoved(GetBounds().origin());
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleWorkAreaChanged() {
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetWidget()->widget_delegate()->OnWorkAreaChanged();
8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleVisibilityChanging(bool visible) {
8043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetVisibilityChanging(visible);
8053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
8063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  native_widget_delegate_->OnNativeWidgetVisibilityChanged(visible);
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleClientSizeChanged(
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Size& new_size) {
813a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (dispatcher())
814a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    OnHostResized(new_size);
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleFrameChanged() {
818f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  SetWindowTransparency();
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Replace the frame and layout the contents.
820f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  GetWidget()->non_client_view()->UpdateFrame();
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleNativeFocus(HWND last_focused_window) {
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): inform the native_widget_delegate_.
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InputMethod* input_method = GetInputMethod();
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (input_method)
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    input_method->OnFocus();
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleNativeBlur(HWND focused_window) {
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(beng): inform the native_widget_delegate_.
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InputMethod* input_method = GetInputMethod();
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (input_method)
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    input_method->OnBlur();
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleMouseEvent(const ui::MouseEvent& event) {
8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SendEventToProcessor(const_cast<ui::MouseEvent*>(&event));
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return event.handled();
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleKeyEvent(const ui::KeyEvent& event) {
8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return false;
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleUntranslatedKeyEvent(
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::KeyEvent& event) {
848a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ui::KeyEvent duplicate_event(event);
8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SendEventToProcessor(&duplicate_event);
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return duplicate_event.handled();
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleTouchEvent(
8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    const ui::TouchEvent& event) {
85558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // HWNDMessageHandler asynchronously processes touch events. Because of this
856a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // it's possible for the aura::WindowEventDispatcher to have been destroyed
857a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // by the time we attempt to process them.
85858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  if (!GetWidget()->GetNativeView())
85958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    return;
8600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
8610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Currently we assume the window that has capture gets touch events too.
862a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  aura::WindowTreeHost* host =
863a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      aura::WindowTreeHost::GetForAcceleratedWidget(GetCapture());
864a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (host) {
8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    DesktopWindowTreeHostWin* target =
866a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        host->window()->GetProperty(kDesktopWindowTreeHostKey);
8670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    if (target && target->HasCapture() && target != this) {
8680f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      POINT target_location(event.location().ToPOINT());
8690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      ClientToScreen(GetHWND(), &target_location);
8700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      ScreenToClient(target->GetHWND(), &target_location);
8710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      ui::TouchEvent target_event(event, static_cast<View*>(NULL),
8720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                  static_cast<View*>(NULL));
8730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      target_event.set_location(gfx::Point(target_location));
8740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      target_event.set_root_location(target_event.location());
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      target->SendEventToProcessor(&target_event);
8760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      return;
8770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    }
8780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  }
8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SendEventToProcessor(const_cast<ui::TouchEvent*>(&event));
8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleIMEMessage(UINT message,
8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                WPARAM w_param,
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                LPARAM l_param,
8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                                LRESULT* result) {
8867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  MSG msg = {};
8877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  msg.hwnd = GetHWND();
8887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  msg.message = message;
8897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  msg.wParam = w_param;
8907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  msg.lParam = l_param;
8917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return desktop_native_widget_aura_->input_method_event_filter()->
8927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      input_method()->OnUntranslatedIMEMessage(msg, result);
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleInputLanguageChange(
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DWORD character_set,
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HKL input_language_id) {
8987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  desktop_native_widget_aura_->input_method_event_filter()->
8997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      input_method()->OnInputLocaleChanged();
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandlePaintAccelerated(
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Rect& invalid_rect) {
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->OnNativeWidgetPaintAccelerated(invalid_rect);
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandlePaint(gfx::Canvas* canvas) {
908cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // It appears possible to get WM_PAINT after WM_DESTROY.
909cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  if (compositor())
910cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    compositor()->ScheduleRedrawRect(gfx::Rect());
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleTooltipNotify(int w_param,
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   NMHDR* l_param,
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                   LRESULT* l_result) {
9164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return tooltip_ && tooltip_->HandleNotify(w_param, l_param, l_result);
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleMenuLoop(bool in_menu_loop) {
9205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (in_menu_loop) {
9215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    tooltip_disabler_.reset(
922a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        new aura::client::ScopedTooltipDisabler(window()));
9235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
9245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    tooltip_disabler_.reset();
9255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
9265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::PreHandleMSG(UINT message,
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            WPARAM w_param,
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            LPARAM l_param,
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            LRESULT* result) {
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::PostHandleMSG(UINT message,
9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             WPARAM w_param,
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             LPARAM l_param) {
9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::HandleScrollEvent(
9415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const ui::ScrollEvent& event) {
9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SendEventToProcessor(const_cast<ui::ScrollEvent*>(&event));
9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return event.handled();
9445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
946cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void DesktopWindowTreeHostWin::HandleWindowSizeChanging() {
9471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (compositor() && need_synchronous_paint_) {
948cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    compositor()->FinishAllRendering();
9491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // If we received the window size changing notification due to a restore or
9501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // maximize operation, then we can reset the need_synchronous_paint_ flag
9511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // here. For a sizing operation, the flag will be reset at the end of the
9521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // operation.
9531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    if (!in_sizing_loop_)
9541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      need_synchronous_paint_ = false;
9551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
956cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
957cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHostWin, private:
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Widget* DesktopWindowTreeHostWin::GetWidget() {
9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->AsWidget();
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const Widget* DesktopWindowTreeHostWin::GetWidget() const {
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return native_widget_delegate_->AsWidget();
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)HWND DesktopWindowTreeHostWin::GetHWND() const {
9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return message_handler_->hwnd();
9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void DesktopWindowTreeHostWin::SetWindowTransparency() {
9740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  bool transparent = ShouldUseNativeFrame() && !IsFullscreen();
975a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  compositor()->SetHostHasTransparentBackground(transparent);
976a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window()->SetTransparent(transparent);
977f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  content_window_->SetTransparent(transparent);
9780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
9790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
9805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool DesktopWindowTreeHostWin::IsModalWindowActive() const {
9814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // This function can get called during window creation which occurs before
982a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // dispatcher() has been created.
983a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!dispatcher())
9844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return false;
9854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  aura::Window::Windows::const_iterator index;
987a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (index = window()->children().begin();
988a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       index != window()->children().end();
9894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)       ++index) {
9904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    if ((*index)->GetProperty(aura::client::kModalKey) !=
9914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        ui:: MODAL_TYPE_NONE && (*index)->TargetVisibility())
9924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      return true;
9934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
9944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return false;
9954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
9964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)////////////////////////////////////////////////////////////////////////////////
9985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// DesktopWindowTreeHost, public:
9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    internal::NativeWidgetDelegate* native_widget_delegate,
10031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    DesktopNativeWidgetAura* desktop_native_widget_aura) {
10045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return new DesktopWindowTreeHostWin(native_widget_delegate,
10051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                      desktop_native_widget_aura);
10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace views
1009