Home | History | Annotate | Download | only in desktop_aura
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h"
      6 
      7 #include "base/win/metro.h"
      8 #include "third_party/skia/include/core/SkPath.h"
      9 #include "third_party/skia/include/core/SkRegion.h"
     10 #include "ui/aura/client/aura_constants.h"
     11 #include "ui/aura/client/cursor_client.h"
     12 #include "ui/aura/focus_manager.h"
     13 #include "ui/aura/root_window.h"
     14 #include "ui/aura/window_property.h"
     15 #include "ui/base/cursor/cursor_loader_win.h"
     16 #include "ui/base/ime/input_method.h"
     17 #include "ui/base/ime/win/tsf_bridge.h"
     18 #include "ui/base/win/dpi.h"
     19 #include "ui/base/win/shell.h"
     20 #include "ui/gfx/insets.h"
     21 #include "ui/gfx/native_widget_types.h"
     22 #include "ui/gfx/path_win.h"
     23 #include "ui/native_theme/native_theme_aura.h"
     24 #include "ui/native_theme/native_theme_win.h"
     25 #include "ui/views/corewm/compound_event_filter.h"
     26 #include "ui/views/corewm/corewm_switches.h"
     27 #include "ui/views/corewm/cursor_manager.h"
     28 #include "ui/views/corewm/focus_controller.h"
     29 #include "ui/views/corewm/input_method_event_filter.h"
     30 #include "ui/views/corewm/window_animations.h"
     31 #include "ui/views/ime/input_method_bridge.h"
     32 #include "ui/views/widget/desktop_aura/desktop_activation_client.h"
     33 #include "ui/views/widget/desktop_aura/desktop_capture_client.h"
     34 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
     35 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
     36 #include "ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h"
     37 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
     38 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
     39 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
     40 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
     41 #include "ui/views/widget/root_view.h"
     42 #include "ui/views/widget/widget_delegate.h"
     43 #include "ui/views/widget/widget_hwnd_utils.h"
     44 #include "ui/views/win/fullscreen_handler.h"
     45 #include "ui/views/win/hwnd_message_handler.h"
     46 #include "ui/views/window/native_frame_view.h"
     47 
     48 namespace views {
     49 
     50 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL);
     51 
     52 ////////////////////////////////////////////////////////////////////////////////
     53 // DesktopRootWindowHostWin, public:
     54 
     55 DesktopRootWindowHostWin::DesktopRootWindowHostWin(
     56     internal::NativeWidgetDelegate* native_widget_delegate,
     57     DesktopNativeWidgetAura* desktop_native_widget_aura,
     58     const gfx::Rect& initial_bounds)
     59     : root_window_(NULL),
     60       message_handler_(new HWNDMessageHandler(this)),
     61       native_widget_delegate_(native_widget_delegate),
     62       desktop_native_widget_aura_(desktop_native_widget_aura),
     63       root_window_host_delegate_(NULL),
     64       content_window_(NULL),
     65       should_animate_window_close_(false),
     66       pending_close_(false),
     67       has_non_client_view_(false) {
     68 }
     69 
     70 DesktopRootWindowHostWin::~DesktopRootWindowHostWin() {
     71   if (corewm::UseFocusControllerOnDesktop()) {
     72     aura::client::SetFocusClient(root_window_, NULL);
     73     aura::client::SetActivationClient(root_window_, NULL);
     74   }
     75 }
     76 
     77 // static
     78 aura::Window* DesktopRootWindowHostWin::GetContentWindowForHWND(HWND hwnd) {
     79   aura::RootWindow* root = aura::RootWindow::GetForAcceleratedWidget(hwnd);
     80   return root ? root->GetProperty(kContentWindowForRootWindow) : NULL;
     81 }
     82 
     83 // static
     84 ui::NativeTheme* DesktopRootWindowHost::GetNativeTheme(aura::Window* window) {
     85   // Use NativeThemeWin for windows shown on the desktop, those not on the
     86   // desktop come from Ash and get NativeThemeAura.
     87   aura::RootWindow* root = window ? window->GetRootWindow() : NULL;
     88   if (root) {
     89     HWND root_hwnd = root->GetAcceleratedWidget();
     90     if (root_hwnd &&
     91         DesktopRootWindowHostWin::GetContentWindowForHWND(root_hwnd)) {
     92       return ui::NativeThemeWin::instance();
     93     }
     94   }
     95   return ui::NativeThemeAura::instance();
     96 }
     97 
     98 ////////////////////////////////////////////////////////////////////////////////
     99 // DesktopRootWindowHostWin, DesktopRootWindowHost implementation:
    100 
    101 aura::RootWindow* DesktopRootWindowHostWin::Init(
    102     aura::Window* content_window,
    103     const Widget::InitParams& params) {
    104   // TODO(beng): SetInitParams().
    105   content_window_ = content_window;
    106 
    107   ConfigureWindowStyles(message_handler_.get(), params,
    108                         GetWidget()->widget_delegate(),
    109                         native_widget_delegate_);
    110 
    111   HWND parent_hwnd = NULL;
    112   aura::Window* parent_window = params.parent;
    113   if (parent_window)
    114     parent_hwnd = parent_window->GetRootWindow()->GetAcceleratedWidget();
    115 
    116   message_handler_->set_remove_standard_frame(params.remove_standard_frame);
    117 
    118   has_non_client_view_ = Widget::RequiresNonClientView(params.type);
    119 
    120   gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(params.bounds);
    121   message_handler_->Init(parent_hwnd, pixel_bounds);
    122 
    123   aura::RootWindow::CreateParams rw_params(params.bounds);
    124   rw_params.host = this;
    125   root_window_ = new aura::RootWindow(rw_params);
    126 
    127   // TODO(beng): We probably need to move these two calls to some function that
    128   //             can change depending on the native-ness of the frame. For right
    129   //             now in the hack-n-slash days of win-aura, we can just
    130   //             unilaterally turn this on.
    131   root_window_->compositor()->SetHostHasTransparentBackground(true);
    132   root_window_->SetTransparent(true);
    133 
    134   root_window_->Init();
    135   root_window_->AddChild(content_window_);
    136 
    137   capture_client_.reset(new views::DesktopCaptureClient(root_window_));
    138   aura::client::SetCaptureClient(root_window_, capture_client_.get());
    139 
    140   if (corewm::UseFocusControllerOnDesktop()) {
    141     corewm::FocusController* focus_controller =
    142         new corewm::FocusController(new DesktopFocusRules);
    143     focus_client_.reset(focus_controller);
    144     aura::client::SetFocusClient(root_window_, focus_controller);
    145     aura::client::SetActivationClient(root_window_, focus_controller);
    146     root_window_->AddPreTargetHandler(focus_controller);
    147   } else {
    148     focus_client_.reset(new aura::FocusManager);
    149     aura::client::SetFocusClient(root_window_, focus_client_.get());
    150     activation_client_.reset(new DesktopActivationClient(root_window_));
    151   }
    152 
    153   dispatcher_client_.reset(new DesktopDispatcherClient);
    154   aura::client::SetDispatcherClient(root_window_,
    155                                     dispatcher_client_.get());
    156 
    157   cursor_client_.reset(
    158       new views::corewm::CursorManager(
    159           scoped_ptr<corewm::NativeCursorManager>(
    160               new views::DesktopNativeCursorManager(
    161                   root_window_,
    162                   scoped_ptr<DesktopCursorLoaderUpdater>()))));
    163   aura::client::SetCursorClient(root_window_,
    164                                 cursor_client_.get());
    165 
    166   position_client_.reset(new DesktopScreenPositionClient());
    167   aura::client::SetScreenPositionClient(root_window_,
    168                                         position_client_.get());
    169 
    170   desktop_native_widget_aura_->InstallInputMethodEventFilter(root_window_);
    171 
    172   drag_drop_client_.reset(new DesktopDragDropClientWin(root_window_,
    173                                                        GetHWND()));
    174   aura::client::SetDragDropClient(root_window_, drag_drop_client_.get());
    175 
    176   focus_client_->FocusWindow(content_window_);
    177   root_window_->SetProperty(kContentWindowForRootWindow, content_window_);
    178 
    179   aura::client::SetAnimationHost(content_window_, this);
    180 
    181   should_animate_window_close_ =
    182       content_window_->type() != aura::client::WINDOW_TYPE_NORMAL &&
    183       !views::corewm::WindowAnimationsDisabled(content_window_);
    184 
    185   return root_window_;
    186 }
    187 
    188 void DesktopRootWindowHostWin::InitFocus(aura::Window* window) {
    189   focus_client_->FocusWindow(window);
    190 }
    191 
    192 void DesktopRootWindowHostWin::Close() {
    193   if (should_animate_window_close_) {
    194     pending_close_ = true;
    195     content_window_->Hide();
    196     const bool is_animating =
    197         content_window_->layer()->GetAnimator()->IsAnimatingProperty(
    198             ui::LayerAnimationElement::VISIBILITY);
    199     // Animation may not start for a number of reasons.
    200     if (!is_animating)
    201       message_handler_->Close();
    202     // else case, OnWindowHidingAnimationCompleted does the actual Close.
    203   } else {
    204     message_handler_->Close();
    205   }
    206 }
    207 
    208 void DesktopRootWindowHostWin::CloseNow() {
    209   message_handler_->CloseNow();
    210 }
    211 
    212 aura::RootWindowHost* DesktopRootWindowHostWin::AsRootWindowHost() {
    213   return this;
    214 }
    215 
    216 void DesktopRootWindowHostWin::ShowWindowWithState(
    217     ui::WindowShowState show_state) {
    218   message_handler_->ShowWindowWithState(show_state);
    219 }
    220 
    221 void DesktopRootWindowHostWin::ShowMaximizedWithBounds(
    222     const gfx::Rect& restored_bounds) {
    223   gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(restored_bounds);
    224   message_handler_->ShowMaximizedWithBounds(pixel_bounds);
    225 }
    226 
    227 bool DesktopRootWindowHostWin::IsVisible() const {
    228   return message_handler_->IsVisible();
    229 }
    230 
    231 void DesktopRootWindowHostWin::SetSize(const gfx::Size& size) {
    232   gfx::Size size_in_pixels = ui::win::DIPToScreenSize(size);
    233   message_handler_->SetSize(size_in_pixels);
    234 }
    235 
    236 void DesktopRootWindowHostWin::CenterWindow(const gfx::Size& size) {
    237   gfx::Size size_in_pixels = ui::win::DIPToScreenSize(size);
    238   message_handler_->CenterWindow(size_in_pixels);
    239 }
    240 
    241 void DesktopRootWindowHostWin::GetWindowPlacement(
    242     gfx::Rect* bounds,
    243     ui::WindowShowState* show_state) const {
    244   message_handler_->GetWindowPlacement(bounds, show_state);
    245   *bounds = ui::win::ScreenToDIPRect(*bounds);
    246 }
    247 
    248 gfx::Rect DesktopRootWindowHostWin::GetWindowBoundsInScreen() const {
    249   gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen();
    250   return ui::win::ScreenToDIPRect(pixel_bounds);
    251 }
    252 
    253 gfx::Rect DesktopRootWindowHostWin::GetClientAreaBoundsInScreen() const {
    254   gfx::Rect pixel_bounds = message_handler_->GetClientAreaBoundsInScreen();
    255   return ui::win::ScreenToDIPRect(pixel_bounds);
    256 }
    257 
    258 gfx::Rect DesktopRootWindowHostWin::GetRestoredBounds() const {
    259   gfx::Rect pixel_bounds = message_handler_->GetRestoredBounds();
    260   return ui::win::ScreenToDIPRect(pixel_bounds);
    261 }
    262 
    263 gfx::Rect DesktopRootWindowHostWin::GetWorkAreaBoundsInScreen() const {
    264   MONITORINFO monitor_info;
    265   monitor_info.cbSize = sizeof(monitor_info);
    266   GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(),
    267                                    MONITOR_DEFAULTTONEAREST),
    268                  &monitor_info);
    269   gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork);
    270   return ui::win::ScreenToDIPRect(pixel_bounds);
    271 }
    272 
    273 void DesktopRootWindowHostWin::SetShape(gfx::NativeRegion native_region) {
    274   SkPath path;
    275   native_region->getBoundaryPath(&path);
    276   message_handler_->SetRegion(gfx::CreateHRGNFromSkPath(path));
    277 }
    278 
    279 void DesktopRootWindowHostWin::Activate() {
    280   message_handler_->Activate();
    281 }
    282 
    283 void DesktopRootWindowHostWin::Deactivate() {
    284   message_handler_->Deactivate();
    285 }
    286 
    287 bool DesktopRootWindowHostWin::IsActive() const {
    288   return message_handler_->IsActive();
    289 }
    290 
    291 void DesktopRootWindowHostWin::Maximize() {
    292   message_handler_->Maximize();
    293 }
    294 
    295 void DesktopRootWindowHostWin::Minimize() {
    296   message_handler_->Minimize();
    297 }
    298 
    299 void DesktopRootWindowHostWin::Restore() {
    300   message_handler_->Restore();
    301 }
    302 
    303 bool DesktopRootWindowHostWin::IsMaximized() const {
    304   return message_handler_->IsMaximized();
    305 }
    306 
    307 bool DesktopRootWindowHostWin::IsMinimized() const {
    308   return message_handler_->IsMinimized();
    309 }
    310 
    311 bool DesktopRootWindowHostWin::HasCapture() const {
    312   return message_handler_->HasCapture();
    313 }
    314 
    315 void DesktopRootWindowHostWin::SetAlwaysOnTop(bool always_on_top) {
    316   message_handler_->SetAlwaysOnTop(always_on_top);
    317 }
    318 
    319 void DesktopRootWindowHostWin::SetWindowTitle(const string16& title) {
    320   message_handler_->SetTitle(title);
    321 }
    322 
    323 void DesktopRootWindowHostWin::ClearNativeFocus() {
    324   message_handler_->ClearNativeFocus();
    325 }
    326 
    327 Widget::MoveLoopResult DesktopRootWindowHostWin::RunMoveLoop(
    328     const gfx::Vector2d& drag_offset,
    329     Widget::MoveLoopSource source) {
    330   return message_handler_->RunMoveLoop(drag_offset) ?
    331       Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED;
    332 }
    333 
    334 void DesktopRootWindowHostWin::EndMoveLoop() {
    335   message_handler_->EndMoveLoop();
    336 }
    337 
    338 void DesktopRootWindowHostWin::SetVisibilityChangedAnimationsEnabled(
    339     bool value) {
    340   message_handler_->SetVisibilityChangedAnimationsEnabled(value);
    341   content_window_->SetProperty(aura::client::kAnimationsDisabledKey, !value);
    342 }
    343 
    344 bool DesktopRootWindowHostWin::ShouldUseNativeFrame() {
    345   return ui::win::IsAeroGlassEnabled();
    346 }
    347 
    348 void DesktopRootWindowHostWin::FrameTypeChanged() {
    349   message_handler_->FrameTypeChanged();
    350 }
    351 
    352 NonClientFrameView* DesktopRootWindowHostWin::CreateNonClientFrameView() {
    353   return GetWidget()->ShouldUseNativeFrame() ?
    354       new NativeFrameView(GetWidget()) : NULL;
    355 }
    356 
    357 void DesktopRootWindowHostWin::SetFullscreen(bool fullscreen) {
    358   message_handler_->fullscreen_handler()->SetFullscreen(fullscreen);
    359 }
    360 
    361 bool DesktopRootWindowHostWin::IsFullscreen() const {
    362   return message_handler_->fullscreen_handler()->fullscreen();
    363 }
    364 
    365 void DesktopRootWindowHostWin::SetOpacity(unsigned char opacity) {
    366   message_handler_->SetOpacity(static_cast<BYTE>(opacity));
    367   content_window_->layer()->SetOpacity(opacity / 255.0);
    368   GetWidget()->GetRootView()->SchedulePaint();
    369 }
    370 
    371 void DesktopRootWindowHostWin::SetWindowIcons(
    372     const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon) {
    373   message_handler_->SetWindowIcons(window_icon, app_icon);
    374 }
    375 
    376 void DesktopRootWindowHostWin::InitModalType(ui::ModalType modal_type) {
    377   message_handler_->InitModalType(modal_type);
    378 }
    379 
    380 void DesktopRootWindowHostWin::FlashFrame(bool flash_frame) {
    381   message_handler_->FlashFrame(flash_frame);
    382 }
    383 
    384 void DesktopRootWindowHostWin::OnNativeWidgetFocus() {
    385   // HWNDMessageHandler will perform the proper updating on its own.
    386 }
    387 
    388 void DesktopRootWindowHostWin::OnNativeWidgetBlur() {
    389 }
    390 
    391 void DesktopRootWindowHostWin::SetInactiveRenderingDisabled(
    392     bool disable_inactive) {
    393   // Force the non-client area (most notably the title bar) to paint as either
    394   // active or inactive, depending on the input.
    395   SendMessage(message_handler_->hwnd(), WM_NCACTIVATE, !!disable_inactive, 0);
    396 }
    397 
    398 ////////////////////////////////////////////////////////////////////////////////
    399 // DesktopRootWindowHostWin, RootWindowHost implementation:
    400 
    401 
    402 void DesktopRootWindowHostWin::SetDelegate(
    403     aura::RootWindowHostDelegate* delegate) {
    404   root_window_host_delegate_ = delegate;
    405 }
    406 
    407 aura::RootWindow* DesktopRootWindowHostWin::GetRootWindow() {
    408   return root_window_;
    409 }
    410 
    411 gfx::AcceleratedWidget DesktopRootWindowHostWin::GetAcceleratedWidget() {
    412   return message_handler_->hwnd();
    413 }
    414 
    415 void DesktopRootWindowHostWin::Show() {
    416   message_handler_->Show();
    417 }
    418 
    419 void DesktopRootWindowHostWin::Hide() {
    420   if (!pending_close_)
    421     message_handler_->Hide();
    422 }
    423 
    424 void DesktopRootWindowHostWin::ToggleFullScreen() {
    425 }
    426 
    427 // GetBounds and SetBounds work in pixel coordinates, whereas other get/set
    428 // methods work in DIP.
    429 
    430 gfx::Rect DesktopRootWindowHostWin::GetBounds() const {
    431   // Match the logic in HWNDMessageHandler::ClientAreaSizeChanged().
    432   gfx::Rect bounds(WidgetSizeIsClientSize() ?
    433       message_handler_->GetClientAreaBoundsInScreen() :
    434       message_handler_->GetWindowBoundsInScreen());
    435   gfx::Rect without_expansion(bounds.x() - window_expansion_.x(),
    436                               bounds.y() - window_expansion_.y(),
    437                               bounds.width() - window_expansion_.width(),
    438                               bounds.height() - window_expansion_.height());
    439   return without_expansion;
    440 }
    441 
    442 void DesktopRootWindowHostWin::SetBounds(const gfx::Rect& bounds) {
    443   gfx::Rect expanded(bounds.x() + window_expansion_.x(),
    444                      bounds.y() + window_expansion_.y(),
    445                      bounds.width() + window_expansion_.width(),
    446                      bounds.height() + window_expansion_.height());
    447   message_handler_->SetBounds(expanded);
    448 }
    449 
    450 gfx::Insets DesktopRootWindowHostWin::GetInsets() const {
    451   return gfx::Insets();
    452 }
    453 
    454 void DesktopRootWindowHostWin::SetInsets(const gfx::Insets& insets) {
    455 }
    456 
    457 gfx::Point DesktopRootWindowHostWin::GetLocationOnNativeScreen() const {
    458   return GetBounds().origin();
    459 }
    460 
    461 void DesktopRootWindowHostWin::SetCapture() {
    462   message_handler_->SetCapture();
    463 }
    464 
    465 void DesktopRootWindowHostWin::ReleaseCapture() {
    466   message_handler_->ReleaseCapture();
    467 }
    468 
    469 void DesktopRootWindowHostWin::SetCursor(gfx::NativeCursor cursor) {
    470   ui::CursorLoaderWin cursor_loader;
    471   cursor_loader.SetPlatformCursor(&cursor);
    472 
    473   message_handler_->SetCursor(cursor.platform());
    474 }
    475 
    476 bool DesktopRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
    477   aura::client::CursorClient* cursor_client =
    478       aura::client::GetCursorClient(GetRootWindow());
    479   if (cursor_client && !cursor_client->IsMouseEventsEnabled()) {
    480     *location_return = gfx::Point(0, 0);
    481     return false;
    482   }
    483   POINT pt = {0};
    484   ::GetCursorPos(&pt);
    485   *location_return =
    486       gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y));
    487   return true;
    488 }
    489 
    490 bool DesktopRootWindowHostWin::ConfineCursorToRootWindow() {
    491   return false;
    492 }
    493 
    494 void DesktopRootWindowHostWin::UnConfineCursor() {
    495 }
    496 
    497 void DesktopRootWindowHostWin::OnCursorVisibilityChanged(bool show) {
    498 }
    499 
    500 void DesktopRootWindowHostWin::MoveCursorTo(const gfx::Point& location) {
    501   POINT cursor_location = location.ToPOINT();
    502   ::ClientToScreen(GetHWND(), &cursor_location);
    503   ::SetCursorPos(cursor_location.x, cursor_location.y);
    504 }
    505 
    506 void DesktopRootWindowHostWin::SetFocusWhenShown(bool focus_when_shown) {
    507 }
    508 
    509 bool DesktopRootWindowHostWin::CopyAreaToSkCanvas(
    510     const gfx::Rect& source_bounds,
    511     const gfx::Point& dest_offset,
    512     SkCanvas* canvas) {
    513   NOTIMPLEMENTED();
    514   return false;
    515 }
    516 
    517 void DesktopRootWindowHostWin::PostNativeEvent(
    518     const base::NativeEvent& native_event) {
    519 }
    520 
    521 void DesktopRootWindowHostWin::OnDeviceScaleFactorChanged(
    522     float device_scale_factor) {
    523 }
    524 
    525 void DesktopRootWindowHostWin::PrepareForShutdown() {
    526 }
    527 
    528 ////////////////////////////////////////////////////////////////////////////////
    529 // DesktopRootWindowHostWin, aura::AnimationHost implementation:
    530 
    531 void DesktopRootWindowHostWin::SetHostTransitionBounds(
    532     const gfx::Rect& bounds) {
    533   gfx::Rect bounds_without_expansion = GetBounds();
    534   window_expansion_ = bounds;
    535   SetBounds(bounds_without_expansion);
    536 }
    537 
    538 void DesktopRootWindowHostWin::OnWindowHidingAnimationCompleted() {
    539   if (pending_close_)
    540     message_handler_->Close();
    541 }
    542 
    543 ////////////////////////////////////////////////////////////////////////////////
    544 // DesktopRootWindowHostWin, HWNDMessageHandlerDelegate implementation:
    545 
    546 bool DesktopRootWindowHostWin::IsWidgetWindow() const {
    547   return has_non_client_view_;
    548 }
    549 
    550 bool DesktopRootWindowHostWin::IsUsingCustomFrame() const {
    551   return !GetWidget()->ShouldUseNativeFrame();
    552 }
    553 
    554 void DesktopRootWindowHostWin::SchedulePaint() {
    555   GetWidget()->GetRootView()->SchedulePaint();
    556 }
    557 
    558 void DesktopRootWindowHostWin::EnableInactiveRendering() {
    559   native_widget_delegate_->EnableInactiveRendering();
    560 }
    561 
    562 bool DesktopRootWindowHostWin::IsInactiveRenderingDisabled() {
    563   return native_widget_delegate_->IsInactiveRenderingDisabled();
    564 }
    565 
    566 bool DesktopRootWindowHostWin::CanResize() const {
    567   return GetWidget()->widget_delegate()->CanResize();
    568 }
    569 
    570 bool DesktopRootWindowHostWin::CanMaximize() const {
    571   return GetWidget()->widget_delegate()->CanMaximize();
    572 }
    573 
    574 bool DesktopRootWindowHostWin::CanActivate() const {
    575   return native_widget_delegate_->CanActivate();
    576 }
    577 
    578 bool DesktopRootWindowHostWin::WidgetSizeIsClientSize() const {
    579   const Widget* widget = GetWidget()->GetTopLevelWidget();
    580   return IsMaximized() || (widget && widget->ShouldUseNativeFrame());
    581 }
    582 
    583 bool DesktopRootWindowHostWin::CanSaveFocus() const {
    584   return GetWidget()->is_top_level();
    585 }
    586 
    587 void DesktopRootWindowHostWin::SaveFocusOnDeactivate() {
    588   GetWidget()->GetFocusManager()->StoreFocusedView(true);
    589 }
    590 
    591 void DesktopRootWindowHostWin::RestoreFocusOnActivate() {
    592   RestoreFocusOnEnable();
    593 }
    594 
    595 void DesktopRootWindowHostWin::RestoreFocusOnEnable() {
    596   GetWidget()->GetFocusManager()->RestoreFocusedView();
    597 }
    598 
    599 bool DesktopRootWindowHostWin::IsModal() const {
    600   return native_widget_delegate_->IsModal();
    601 }
    602 
    603 int DesktopRootWindowHostWin::GetInitialShowState() const {
    604   return SW_SHOWNORMAL;
    605 }
    606 
    607 bool DesktopRootWindowHostWin::WillProcessWorkAreaChange() const {
    608   return GetWidget()->widget_delegate()->WillProcessWorkAreaChange();
    609 }
    610 
    611 int DesktopRootWindowHostWin::GetNonClientComponent(
    612     const gfx::Point& point) const {
    613   gfx::Point dip_position = ui::win::ScreenToDIPPoint(point);
    614   return native_widget_delegate_->GetNonClientComponent(dip_position);
    615 }
    616 
    617 void DesktopRootWindowHostWin::GetWindowMask(const gfx::Size& size,
    618                                              gfx::Path* path) {
    619   if (GetWidget()->non_client_view())
    620     GetWidget()->non_client_view()->GetWindowMask(size, path);
    621 }
    622 
    623 bool DesktopRootWindowHostWin::GetClientAreaInsets(gfx::Insets* insets) const {
    624   return false;
    625 }
    626 
    627 void DesktopRootWindowHostWin::GetMinMaxSize(gfx::Size* min_size,
    628                                              gfx::Size* max_size) const {
    629   *min_size = native_widget_delegate_->GetMinimumSize();
    630   *max_size = native_widget_delegate_->GetMaximumSize();
    631 }
    632 
    633 gfx::Size DesktopRootWindowHostWin::GetRootViewSize() const {
    634   return GetWidget()->GetRootView()->size();
    635 }
    636 
    637 void DesktopRootWindowHostWin::ResetWindowControls() {
    638   GetWidget()->non_client_view()->ResetWindowControls();
    639 }
    640 
    641 void DesktopRootWindowHostWin::PaintLayeredWindow(gfx::Canvas* canvas) {
    642   GetWidget()->GetRootView()->Paint(canvas);
    643 }
    644 
    645 gfx::NativeViewAccessible DesktopRootWindowHostWin::GetNativeViewAccessible() {
    646   return GetWidget()->GetRootView()->GetNativeViewAccessible();
    647 }
    648 
    649 InputMethod* DesktopRootWindowHostWin::GetInputMethod() {
    650   return GetWidget()->GetInputMethodDirect();
    651 }
    652 
    653 bool DesktopRootWindowHostWin::ShouldHandleSystemCommands() const {
    654   return GetWidget()->widget_delegate()->ShouldHandleSystemCommands();
    655 }
    656 
    657 void DesktopRootWindowHostWin::HandleAppDeactivated() {
    658   native_widget_delegate_->EnableInactiveRendering();
    659 }
    660 
    661 void DesktopRootWindowHostWin::HandleActivationChanged(bool active) {
    662   if (active)
    663     root_window_host_delegate_->OnHostActivated();
    664   native_widget_delegate_->OnNativeWidgetActivationChanged(active);
    665   // If we're not active we need to deactivate the corresponding aura::Window.
    666   // This way if a child widget is active it gets correctly deactivated (child
    667   // widgets don't get native desktop activation changes, only aura activation
    668   // changes).
    669   if (!active) {
    670     aura::client::ActivationClient* activation_client =
    671         aura::client::GetActivationClient(root_window_);
    672     if (activation_client) {
    673       aura::Window* active_window = activation_client->GetActiveWindow();
    674       if (active_window)
    675         activation_client->DeactivateWindow(active_window);
    676     }
    677   }
    678 }
    679 
    680 bool DesktopRootWindowHostWin::HandleAppCommand(short command) {
    681   // We treat APPCOMMAND ids as an extension of our command namespace, and just
    682   // let the delegate figure out what to do...
    683   return GetWidget()->widget_delegate() &&
    684       GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
    685 }
    686 
    687 void DesktopRootWindowHostWin::HandleCancelMode() {
    688   root_window_host_delegate_->OnHostCancelMode();
    689 }
    690 
    691 void DesktopRootWindowHostWin::HandleCaptureLost() {
    692   root_window_host_delegate_->OnHostLostWindowCapture();
    693   native_widget_delegate_->OnMouseCaptureLost();
    694 }
    695 
    696 void DesktopRootWindowHostWin::HandleClose() {
    697   GetWidget()->Close();
    698 }
    699 
    700 bool DesktopRootWindowHostWin::HandleCommand(int command) {
    701   return GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
    702 }
    703 
    704 void DesktopRootWindowHostWin::HandleAccelerator(
    705     const ui::Accelerator& accelerator) {
    706   GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator);
    707 }
    708 
    709 void DesktopRootWindowHostWin::HandleCreate() {
    710   // TODO(beng): moar
    711   NOTIMPLEMENTED();
    712 
    713   native_widget_delegate_->OnNativeWidgetCreated(true);
    714 
    715   // 1. Window property association
    716   // 2. MouseWheel.
    717 }
    718 
    719 void DesktopRootWindowHostWin::HandleDestroying() {
    720   drag_drop_client_->OnNativeWidgetDestroying(GetHWND());
    721   native_widget_delegate_->OnNativeWidgetDestroying();
    722 }
    723 
    724 void DesktopRootWindowHostWin::HandleDestroyed() {
    725   desktop_native_widget_aura_->OnHostClosed();
    726 }
    727 
    728 bool DesktopRootWindowHostWin::HandleInitialFocus() {
    729   return GetWidget()->SetInitialFocus();
    730 }
    731 
    732 void DesktopRootWindowHostWin::HandleDisplayChange() {
    733   GetWidget()->widget_delegate()->OnDisplayChanged();
    734 }
    735 
    736 void DesktopRootWindowHostWin::HandleBeginWMSizeMove() {
    737   native_widget_delegate_->OnNativeWidgetBeginUserBoundsChange();
    738 }
    739 
    740 void DesktopRootWindowHostWin::HandleEndWMSizeMove() {
    741   native_widget_delegate_->OnNativeWidgetEndUserBoundsChange();
    742 }
    743 
    744 void DesktopRootWindowHostWin::HandleMove() {
    745   native_widget_delegate_->OnNativeWidgetMove();
    746   if (root_window_host_delegate_)
    747     root_window_host_delegate_->OnHostMoved(GetBounds().origin());
    748 }
    749 
    750 void DesktopRootWindowHostWin::HandleWorkAreaChanged() {
    751   GetWidget()->widget_delegate()->OnWorkAreaChanged();
    752 }
    753 
    754 void DesktopRootWindowHostWin::HandleVisibilityChanged(bool visible) {
    755   native_widget_delegate_->OnNativeWidgetVisibilityChanged(visible);
    756 }
    757 
    758 void DesktopRootWindowHostWin::HandleClientSizeChanged(
    759     const gfx::Size& new_size) {
    760   gfx::Size without_expansion(new_size.width() - window_expansion_.width(),
    761                               new_size.height() - window_expansion_.height());
    762   if (root_window_host_delegate_)
    763     root_window_host_delegate_->OnHostResized(new_size);
    764   // TODO(beng): replace with a layout manager??
    765   gfx::Size dip_size = ui::win::ScreenToDIPSize(without_expansion);
    766   content_window_->SetBounds(gfx::Rect(dip_size));
    767   native_widget_delegate_->OnNativeWidgetSizeChanged(dip_size);
    768 }
    769 
    770 void DesktopRootWindowHostWin::HandleFrameChanged() {
    771   // Replace the frame and layout the contents.
    772   GetWidget()->non_client_view()->UpdateFrame(true);
    773 }
    774 
    775 void DesktopRootWindowHostWin::HandleNativeFocus(HWND last_focused_window) {
    776   // TODO(beng): inform the native_widget_delegate_.
    777   InputMethod* input_method = GetInputMethod();
    778   if (input_method)
    779     input_method->OnFocus();
    780 }
    781 
    782 void DesktopRootWindowHostWin::HandleNativeBlur(HWND focused_window) {
    783   // TODO(beng): inform the native_widget_delegate_.
    784   InputMethod* input_method = GetInputMethod();
    785   if (input_method)
    786     input_method->OnBlur();
    787 }
    788 
    789 bool DesktopRootWindowHostWin::HandleMouseEvent(const ui::MouseEvent& event) {
    790   if (base::win::IsTSFAwareRequired() && event.IsAnyButton())
    791     ui::TSFBridge::GetInstance()->CancelComposition();
    792   return root_window_host_delegate_->OnHostMouseEvent(
    793       const_cast<ui::MouseEvent*>(&event));
    794 }
    795 
    796 bool DesktopRootWindowHostWin::HandleKeyEvent(const ui::KeyEvent& event) {
    797   return false;
    798 }
    799 
    800 bool DesktopRootWindowHostWin::HandleUntranslatedKeyEvent(
    801     const ui::KeyEvent& event) {
    802   scoped_ptr<ui::KeyEvent> duplicate_event(event.Copy());
    803   return static_cast<aura::RootWindowHostDelegate*>(root_window_)->
    804       OnHostKeyEvent(duplicate_event.get());
    805 }
    806 
    807 bool DesktopRootWindowHostWin::HandleTouchEvent(
    808     const ui::TouchEvent& event) {
    809   return root_window_host_delegate_->OnHostTouchEvent(
    810       const_cast<ui::TouchEvent*>(&event));
    811 }
    812 
    813 bool DesktopRootWindowHostWin::HandleIMEMessage(UINT message,
    814                                                 WPARAM w_param,
    815                                                 LPARAM l_param,
    816                                                 LRESULT* result) {
    817   MSG msg = {};
    818   msg.hwnd = GetHWND();
    819   msg.message = message;
    820   msg.wParam = w_param;
    821   msg.lParam = l_param;
    822   return desktop_native_widget_aura_->input_method_event_filter()->
    823       input_method()->OnUntranslatedIMEMessage(msg, result);
    824 }
    825 
    826 void DesktopRootWindowHostWin::HandleInputLanguageChange(
    827     DWORD character_set,
    828     HKL input_language_id) {
    829   desktop_native_widget_aura_->input_method_event_filter()->
    830       input_method()->OnInputLocaleChanged();
    831 }
    832 
    833 bool DesktopRootWindowHostWin::HandlePaintAccelerated(
    834     const gfx::Rect& invalid_rect) {
    835   return native_widget_delegate_->OnNativeWidgetPaintAccelerated(invalid_rect);
    836 }
    837 
    838 void DesktopRootWindowHostWin::HandlePaint(gfx::Canvas* canvas) {
    839   root_window_host_delegate_->OnHostPaint(gfx::Rect());
    840 }
    841 
    842 bool DesktopRootWindowHostWin::HandleTooltipNotify(int w_param,
    843                                                    NMHDR* l_param,
    844                                                    LRESULT* l_result) {
    845   return false;
    846 }
    847 
    848 void DesktopRootWindowHostWin::HandleTooltipMouseMove(UINT message,
    849                                                       WPARAM w_param,
    850                                                       LPARAM l_param) {
    851 }
    852 
    853 bool DesktopRootWindowHostWin::PreHandleMSG(UINT message,
    854                                             WPARAM w_param,
    855                                             LPARAM l_param,
    856                                             LRESULT* result) {
    857   return false;
    858 }
    859 
    860 void DesktopRootWindowHostWin::PostHandleMSG(UINT message,
    861                                              WPARAM w_param,
    862                                              LPARAM l_param) {
    863 }
    864 
    865 ////////////////////////////////////////////////////////////////////////////////
    866 // DesktopRootWindowHostWin, private:
    867 
    868 Widget* DesktopRootWindowHostWin::GetWidget() {
    869   return native_widget_delegate_->AsWidget();
    870 }
    871 
    872 const Widget* DesktopRootWindowHostWin::GetWidget() const {
    873   return native_widget_delegate_->AsWidget();
    874 }
    875 
    876 HWND DesktopRootWindowHostWin::GetHWND() const {
    877   return message_handler_->hwnd();
    878 }
    879 
    880 ////////////////////////////////////////////////////////////////////////////////
    881 // DesktopRootWindowHost, public:
    882 
    883 // static
    884 DesktopRootWindowHost* DesktopRootWindowHost::Create(
    885     internal::NativeWidgetDelegate* native_widget_delegate,
    886     DesktopNativeWidgetAura* desktop_native_widget_aura,
    887     const gfx::Rect& initial_bounds) {
    888   return new DesktopRootWindowHostWin(native_widget_delegate,
    889                                       desktop_native_widget_aura,
    890                                       initial_bounds);
    891 }
    892 
    893 }  // namespace views
    894