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