OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/widget/native_widget_mac.h" | 5 #include "ui/views/widget/native_widget_mac.h" |
6 | 6 |
7 #include <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
9 #include "ui/gfx/font_list.h" | 10 #include "ui/gfx/font_list.h" |
| 11 #include "ui/gfx/canvas_paint_mac.h" |
| 12 #include "ui/gfx/mac/point_utils.h" |
| 13 #include "ui/native_theme/native_theme.h" |
| 14 #import "ui/views/cocoa/bridged_content_view.h" |
| 15 #import "ui/views/cocoa/bridged_native_widget.h" |
| 16 |
| 17 #include "ui/views/ime/input_method_base.h" |
| 18 #include "ui/base/ime/text_input_mode.h" |
10 | 19 |
11 namespace views { | 20 namespace views { |
12 | 21 |
| 22 namespace { |
| 23 |
| 24 class StubInputMethod : public views::InputMethodBase { |
| 25 |
| 26 virtual void OnFocus() OVERRIDE {} |
| 27 virtual void OnBlur() OVERRIDE {} |
| 28 |
| 29 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, |
| 30 NativeEventResult* result) OVERRIDE { |
| 31 return false; |
| 32 } |
| 33 virtual void DispatchKeyEvent(const ui::KeyEvent& event) OVERRIDE {} |
| 34 virtual void OnCaretBoundsChanged(views::View* view) OVERRIDE {} |
| 35 virtual void CancelComposition(views::View* view) OVERRIDE {} |
| 36 virtual void OnInputLocaleChanged() OVERRIDE {} |
| 37 virtual std::string GetInputLocale() OVERRIDE { return ""; } |
| 38 virtual bool IsActive() OVERRIDE { return false; } |
| 39 virtual bool IsCandidatePopupOpen() const OVERRIDE { return false; } |
| 40 virtual void ShowImeIfNeeded() OVERRIDE {} |
| 41 }; |
| 42 |
| 43 } |
| 44 |
| 45 |
13 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
14 // NativeWidgetMac, public: | 47 // NativeWidgetMac, public: |
15 | 48 |
16 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) | 49 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) |
17 : delegate_(delegate), window_(nil) { | 50 : delegate_(delegate), |
| 51 bridge_(new BridgedNativeWidget), |
| 52 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { |
18 } | 53 } |
19 | 54 |
20 NativeWidgetMac::~NativeWidgetMac() { | 55 NativeWidgetMac::~NativeWidgetMac() { |
21 } | 56 } |
22 | 57 |
23 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
24 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: | 59 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: |
25 | 60 |
26 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { | 61 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
| 62 ownership_ = params.ownership; |
| 63 |
27 // TODO(tapted): Convert position into Cocoa's flipped coordinate space. | 64 // TODO(tapted): Convert position into Cocoa's flipped coordinate space. |
28 NSRect content_rect = | 65 NSRect content_rect = |
29 NSMakeRect(0, 0, params.bounds.width(), params.bounds.height()); | 66 NSMakeRect(0, 0, params.bounds.width(), params.bounds.height()); |
30 // TODO(tapted): Determine a good initial style mask from |params|. | 67 // TODO(tapted): Determine a good initial style mask from |params|. |
31 NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | | 68 NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | |
32 NSMiniaturizableWindowMask | NSResizableWindowMask; | 69 NSMiniaturizableWindowMask | NSResizableWindowMask; |
33 window_.reset([[NSWindow alloc] initWithContentRect:content_rect | 70 base::scoped_nsobject<NSWindow> window( |
34 styleMask:style_mask | 71 [[NSWindow alloc] initWithContentRect:content_rect |
35 backing:NSBackingStoreBuffered | 72 styleMask:style_mask |
36 defer:NO]); | 73 backing:NSBackingStoreBuffered |
| 74 defer:NO]); |
| 75 bridge_->Init(window); |
| 76 delegate_->OnNativeWidgetCreated(true); |
37 } | 77 } |
38 | 78 |
39 NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() { | 79 NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() { |
40 return NULL; | 80 return NULL; |
41 } | 81 } |
42 | 82 |
43 bool NativeWidgetMac::ShouldUseNativeFrame() const { | 83 bool NativeWidgetMac::ShouldUseNativeFrame() const { |
44 return false; | 84 return false; |
45 } | 85 } |
46 | 86 |
47 bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const { | 87 bool NativeWidgetMac::ShouldWindowContentsBeTransparent() const { |
48 NOTIMPLEMENTED(); | 88 NOTIMPLEMENTED(); |
49 return false; | 89 return false; |
50 } | 90 } |
51 | 91 |
52 void NativeWidgetMac::FrameTypeChanged() { | 92 void NativeWidgetMac::FrameTypeChanged() { |
53 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
54 } | 94 } |
55 | 95 |
56 Widget* NativeWidgetMac::GetWidget() { | 96 Widget* NativeWidgetMac::GetWidget() { |
57 return delegate_->AsWidget(); | 97 return delegate_->AsWidget(); |
58 } | 98 } |
59 | 99 |
60 const Widget* NativeWidgetMac::GetWidget() const { | 100 const Widget* NativeWidgetMac::GetWidget() const { |
61 return delegate_->AsWidget(); | 101 return delegate_->AsWidget(); |
62 } | 102 } |
63 | 103 |
64 gfx::NativeView NativeWidgetMac::GetNativeView() const { | 104 gfx::NativeView NativeWidgetMac::GetNativeView() const { |
65 return [window_ contentView]; | 105 return bridge_->ns_view(); |
66 } | 106 } |
67 | 107 |
68 gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const { | 108 gfx::NativeWindow NativeWidgetMac::GetNativeWindow() const { |
69 return window_; | 109 return bridge_->ns_window(); |
70 } | 110 } |
71 | 111 |
72 Widget* NativeWidgetMac::GetTopLevelWidget() { | 112 Widget* NativeWidgetMac::GetTopLevelWidget() { |
73 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
74 return GetWidget(); | 114 return GetWidget(); |
75 } | 115 } |
76 | 116 |
77 const ui::Compositor* NativeWidgetMac::GetCompositor() const { | 117 const ui::Compositor* NativeWidgetMac::GetCompositor() const { |
78 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
79 return NULL; | 119 return NULL; |
80 } | 120 } |
81 | 121 |
82 ui::Compositor* NativeWidgetMac::GetCompositor() { | 122 ui::Compositor* NativeWidgetMac::GetCompositor() { |
83 NOTIMPLEMENTED(); | 123 NOTIMPLEMENTED(); |
84 return NULL; | 124 return NULL; |
85 } | 125 } |
86 | 126 |
87 ui::Layer* NativeWidgetMac::GetLayer() { | 127 ui::Layer* NativeWidgetMac::GetLayer() { |
88 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
89 return NULL; | 129 return NULL; |
90 } | 130 } |
91 | 131 |
92 void NativeWidgetMac::ReorderNativeViews() { | 132 void NativeWidgetMac::ReorderNativeViews() { |
93 NOTIMPLEMENTED(); | 133 bridge_->SetRootView(GetWidget()->GetRootView()); |
94 } | 134 } |
95 | 135 |
96 void NativeWidgetMac::ViewRemoved(View* view) { | 136 void NativeWidgetMac::ViewRemoved(View* view) { |
97 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
98 } | 138 } |
99 | 139 |
100 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { | 140 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { |
101 NOTIMPLEMENTED(); | 141 NOTIMPLEMENTED(); |
102 } | 142 } |
103 | 143 |
(...skipping 14 matching lines...) Expand all Loading... |
118 void NativeWidgetMac::ReleaseCapture() { | 158 void NativeWidgetMac::ReleaseCapture() { |
119 NOTIMPLEMENTED(); | 159 NOTIMPLEMENTED(); |
120 } | 160 } |
121 | 161 |
122 bool NativeWidgetMac::HasCapture() const { | 162 bool NativeWidgetMac::HasCapture() const { |
123 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
124 return false; | 164 return false; |
125 } | 165 } |
126 | 166 |
127 InputMethod* NativeWidgetMac::CreateInputMethod() { | 167 InputMethod* NativeWidgetMac::CreateInputMethod() { |
| 168 return new StubInputMethod(); // FIXME |
128 NOTIMPLEMENTED(); | 169 NOTIMPLEMENTED(); |
129 return NULL; | 170 return NULL; |
130 } | 171 } |
131 | 172 |
132 InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() { | 173 InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() { |
133 NOTIMPLEMENTED(); | 174 NOTIMPLEMENTED(); |
134 return NULL; | 175 return NULL; |
135 } | 176 } |
136 | 177 |
137 ui::InputMethod* NativeWidgetMac::GetHostInputMethod() { | 178 ui::InputMethod* NativeWidgetMac::GetHostInputMethod() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 NOTIMPLEMENTED(); | 212 NOTIMPLEMENTED(); |
172 return gfx::Rect(); | 213 return gfx::Rect(); |
173 } | 214 } |
174 | 215 |
175 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 216 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
176 NOTIMPLEMENTED(); | 217 NOTIMPLEMENTED(); |
177 return gfx::Rect(); | 218 return gfx::Rect(); |
178 } | 219 } |
179 | 220 |
180 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { | 221 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
181 NOTIMPLEMENTED(); | 222 NSRect frame_rect = [bridge_->ns_window() |
| 223 frameRectForContentRect:gfx::ScreenRectToNSRect(bounds)]; |
| 224 [bridge_->ns_window() setFrame:frame_rect display:YES animate:NO]; |
182 } | 225 } |
183 | 226 |
184 void NativeWidgetMac::SetSize(const gfx::Size& size) { | 227 void NativeWidgetMac::SetSize(const gfx::Size& size) { |
185 [window_ setContentSize:NSMakeSize(size.width(), size.height())]; | 228 [bridge_->ns_window() setContentSize:NSMakeSize(size.width(), size.height())]; |
186 } | 229 } |
187 | 230 |
188 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { | 231 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { |
189 NOTIMPLEMENTED(); | 232 NOTIMPLEMENTED(); |
190 } | 233 } |
191 | 234 |
192 void NativeWidgetMac::StackAtTop() { | 235 void NativeWidgetMac::StackAtTop() { |
193 NOTIMPLEMENTED(); | 236 NOTIMPLEMENTED(); |
194 } | 237 } |
195 | 238 |
(...skipping 21 matching lines...) Expand all Loading... |
217 NOTIMPLEMENTED(); | 260 NOTIMPLEMENTED(); |
218 } | 261 } |
219 | 262 |
220 void NativeWidgetMac::ShowMaximizedWithBounds( | 263 void NativeWidgetMac::ShowMaximizedWithBounds( |
221 const gfx::Rect& restored_bounds) { | 264 const gfx::Rect& restored_bounds) { |
222 NOTIMPLEMENTED(); | 265 NOTIMPLEMENTED(); |
223 } | 266 } |
224 | 267 |
225 void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) { | 268 void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) { |
226 NOTIMPLEMENTED(); | 269 NOTIMPLEMENTED(); |
| 270 Activate(); |
227 } | 271 } |
228 | 272 |
229 bool NativeWidgetMac::IsVisible() const { | 273 bool NativeWidgetMac::IsVisible() const { |
230 NOTIMPLEMENTED(); | 274 NOTIMPLEMENTED(); |
231 return true; | 275 return true; |
232 } | 276 } |
233 | 277 |
234 void NativeWidgetMac::Activate() { | 278 void NativeWidgetMac::Activate() { |
235 NOTIMPLEMENTED(); | 279 [bridge_->ns_window() makeKeyAndOrderFront:nil]; |
| 280 [NSApp activateIgnoringOtherApps:YES]; |
236 } | 281 } |
237 | 282 |
238 void NativeWidgetMac::Deactivate() { | 283 void NativeWidgetMac::Deactivate() { |
239 NOTIMPLEMENTED(); | 284 NOTIMPLEMENTED(); |
240 } | 285 } |
241 | 286 |
242 bool NativeWidgetMac::IsActive() const { | 287 bool NativeWidgetMac::IsActive() const { |
243 NOTIMPLEMENTED(); | 288 NOTIMPLEMENTED(); |
244 return true; | 289 return false; |
245 } | 290 } |
246 | 291 |
247 void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) { | 292 void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) { |
248 NOTIMPLEMENTED(); | 293 NOTIMPLEMENTED(); |
249 } | 294 } |
250 | 295 |
251 bool NativeWidgetMac::IsAlwaysOnTop() const { | 296 bool NativeWidgetMac::IsAlwaysOnTop() const { |
252 NOTIMPLEMENTED(); | 297 NOTIMPLEMENTED(); |
253 return false; | 298 return false; |
254 } | 299 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 347 |
303 void NativeWidgetMac::RunShellDrag(View* view, | 348 void NativeWidgetMac::RunShellDrag(View* view, |
304 const ui::OSExchangeData& data, | 349 const ui::OSExchangeData& data, |
305 const gfx::Point& location, | 350 const gfx::Point& location, |
306 int operation, | 351 int operation, |
307 ui::DragDropTypes::DragEventSource source) { | 352 ui::DragDropTypes::DragEventSource source) { |
308 NOTIMPLEMENTED(); | 353 NOTIMPLEMENTED(); |
309 } | 354 } |
310 | 355 |
311 void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) { | 356 void NativeWidgetMac::SchedulePaintInRect(const gfx::Rect& rect) { |
| 357 [bridge_->ns_view() setNeedsDisplay:YES]; |
312 NOTIMPLEMENTED(); | 358 NOTIMPLEMENTED(); |
313 } | 359 } |
314 | 360 |
315 void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) { | 361 void NativeWidgetMac::SetCursor(gfx::NativeCursor cursor) { |
316 NOTIMPLEMENTED(); | 362 NOTIMPLEMENTED(); |
317 } | 363 } |
318 | 364 |
319 bool NativeWidgetMac::IsMouseEventsEnabled() const { | 365 bool NativeWidgetMac::IsMouseEventsEnabled() const { |
320 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
321 return true; | 367 return true; |
(...skipping 18 matching lines...) Expand all Loading... |
340 | 386 |
341 void NativeWidgetMac::EndMoveLoop() { | 387 void NativeWidgetMac::EndMoveLoop() { |
342 NOTIMPLEMENTED(); | 388 NOTIMPLEMENTED(); |
343 } | 389 } |
344 | 390 |
345 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 391 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
346 NOTIMPLEMENTED(); | 392 NOTIMPLEMENTED(); |
347 } | 393 } |
348 | 394 |
349 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { | 395 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { |
350 NOTIMPLEMENTED(); | 396 return ui::NativeTheme::instance(); |
351 return NULL; | |
352 } | 397 } |
353 | 398 |
354 void NativeWidgetMac::OnRootViewLayout() const { | 399 void NativeWidgetMac::OnRootViewLayout() const { |
355 NOTIMPLEMENTED(); | 400 NOTIMPLEMENTED(); |
356 } | 401 } |
357 | 402 |
358 void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) { | 403 void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) { |
359 NOTIMPLEMENTED(); | 404 NOTIMPLEMENTED(); |
360 } | 405 } |
361 | 406 |
362 //////////////////////////////////////////////////////////////////////////////// | 407 //////////////////////////////////////////////////////////////////////////////// |
363 // Widget, public: | 408 // Widget, public: |
364 | 409 |
365 bool Widget::ConvertRect(const Widget* source, | 410 bool Widget::ConvertRect(const Widget* source, |
366 const Widget* target, | 411 const Widget* target, |
367 gfx::Rect* rect) { | 412 gfx::Rect* rect) { |
368 return false; | 413 return false; |
369 } | 414 } |
370 | 415 |
371 namespace internal { | 416 namespace internal { |
372 | 417 |
373 //////////////////////////////////////////////////////////////////////////////// | 418 //////////////////////////////////////////////////////////////////////////////// |
374 // internal::NativeWidgetPrivate, public: | 419 // internal::NativeWidgetPrivate, public: |
375 | 420 |
376 // static | 421 // static |
377 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( | 422 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( |
378 internal::NativeWidgetDelegate* delegate) { | 423 internal::NativeWidgetDelegate* delegate) { |
379 NOTIMPLEMENTED(); | 424 // Called e.g. via CreateBubbleWidget(). |
380 return NULL; | 425 return new NativeWidgetMac(delegate); |
381 } | 426 } |
382 | 427 |
383 // static | 428 // static |
384 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( | 429 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( |
385 gfx::NativeView native_view) { | 430 gfx::NativeView native_view) { |
386 NOTIMPLEMENTED(); | 431 NOTIMPLEMENTED(); |
387 return NULL; | 432 return NULL; |
388 } | 433 } |
389 | 434 |
390 // static | 435 // static |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 477 } |
433 | 478 |
434 // static | 479 // static |
435 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { | 480 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { |
436 NOTIMPLEMENTED(); | 481 NOTIMPLEMENTED(); |
437 return gfx::FontList(); | 482 return gfx::FontList(); |
438 } | 483 } |
439 | 484 |
440 } // namespace internal | 485 } // namespace internal |
441 } // namespace views | 486 } // namespace views |
OLD | NEW |