Add ICU message format support
[chromium-blink-merge.git] / ui / aura / window_tree_host_win.cc
blob810b5e1575f5d1ad02abe21ecb05f4e8fee16812
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.
5 #include "ui/aura/window_tree_host_win.h"
7 #include <windows.h>
9 #include <algorithm>
11 #include "base/message_loop/message_loop.h"
12 #include "ui/aura/client/cursor_client.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/base/cursor/cursor_loader_win.h"
15 #include "ui/base/view_prop.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/events/event.h"
18 #include "ui/gfx/display.h"
19 #include "ui/gfx/geometry/insets.h"
20 #include "ui/gfx/native_widget_types.h"
21 #include "ui/gfx/screen.h"
22 #include "ui/platform_window/win/win_window.h"
24 using std::max;
25 using std::min;
27 namespace aura {
29 // static
30 WindowTreeHost* WindowTreeHost::Create(const gfx::Rect& bounds) {
31 return new WindowTreeHostWin(bounds);
34 // static
35 gfx::Size WindowTreeHost::GetNativeScreenSize() {
36 return gfx::Size(GetSystemMetrics(SM_CXSCREEN),
37 GetSystemMetrics(SM_CYSCREEN));
40 WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds)
41 : has_capture_(false),
42 widget_(gfx::kNullAcceleratedWidget),
43 window_(new ui::WinWindow(this, bounds)) {
46 WindowTreeHostWin::~WindowTreeHostWin() {
47 DestroyCompositor();
48 DestroyDispatcher();
49 window_.reset();
52 ui::EventSource* WindowTreeHostWin::GetEventSource() {
53 return this;
56 gfx::AcceleratedWidget WindowTreeHostWin::GetAcceleratedWidget() {
57 return widget_;
60 void WindowTreeHostWin::ShowImpl() {
61 window_->Show();
64 void WindowTreeHostWin::HideImpl() {
65 window_->Hide();
68 gfx::Rect WindowTreeHostWin::GetBounds() const {
69 return window_->GetBounds();
72 void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
73 window_->SetBounds(bounds);
76 gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const {
77 return window_->GetBounds().origin();
80 void WindowTreeHostWin::SetCapture() {
81 if (!has_capture_) {
82 has_capture_ = true;
83 window_->SetCapture();
87 void WindowTreeHostWin::ReleaseCapture() {
88 if (has_capture_)
89 window_->ReleaseCapture();
92 void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
93 // Custom web cursors are handled directly.
94 if (native_cursor == ui::kCursorCustom)
95 return;
97 ui::CursorLoaderWin cursor_loader;
98 cursor_loader.SetPlatformCursor(&native_cursor);
99 ::SetCursor(native_cursor.platform());
102 void WindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
103 // Deliberately not implemented.
106 void WindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
107 NOTIMPLEMENTED();
110 void WindowTreeHostWin::OnBoundsChanged(const gfx::Rect& new_bounds) {
111 gfx::Rect old_bounds = bounds_;
112 bounds_ = new_bounds;
113 if (bounds_.origin() != old_bounds.origin())
114 OnHostMoved(bounds_.origin());
115 if (bounds_.size() != old_bounds.size())
116 OnHostResized(bounds_.size());
119 void WindowTreeHostWin::OnDamageRect(const gfx::Rect& damage_rect) {
120 compositor()->ScheduleRedrawRect(damage_rect);
123 void WindowTreeHostWin::DispatchEvent(ui::Event* event) {
124 ui::EventDispatchDetails details = SendEventToProcessor(event);
125 if (details.dispatcher_destroyed)
126 event->SetHandled();
129 void WindowTreeHostWin::OnCloseRequest() {
130 // TODO: this obviously shouldn't be here.
131 base::MessageLoopForUI::current()->Quit();
134 void WindowTreeHostWin::OnClosed() {
137 void WindowTreeHostWin::OnWindowStateChanged(
138 ui::PlatformWindowState new_state) {
141 void WindowTreeHostWin::OnLostCapture() {
142 if (has_capture_) {
143 has_capture_ = false;
144 OnHostLostWindowCapture();
148 void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
149 gfx::AcceleratedWidget widget,
150 float device_pixel_ratio) {
151 widget_ = widget;
152 CreateCompositor(widget);
155 void WindowTreeHostWin::OnActivationChanged(bool active) {
156 if (active)
157 OnHostActivated();
160 } // namespace aura