Chromium Code Reviews| 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 #import "ui/views/cocoa/bridged_content_view.h" | 5 #import "ui/views/cocoa/bridged_content_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
| 12 #include "ui/base/cocoa/cocoa_base_utils.h" | 12 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 13 #include "ui/base/dragdrop/drag_drop_types.h" | |
| 14 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" | |
| 13 #include "ui/base/ime/input_method.h" | 15 #include "ui/base/ime/input_method.h" |
| 14 #include "ui/base/ime/text_input_client.h" | 16 #include "ui/base/ime/text_input_client.h" |
| 15 #include "ui/compositor/canvas_painter.h" | 17 #include "ui/compositor/canvas_painter.h" |
| 16 #import "ui/events/cocoa/cocoa_event_utils.h" | 18 #import "ui/events/cocoa/cocoa_event_utils.h" |
| 17 #include "ui/events/keycodes/dom/dom_code.h" | 19 #include "ui/events/keycodes/dom/dom_code.h" |
| 18 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 20 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 19 #include "ui/gfx/canvas_paint_mac.h" | 21 #include "ui/gfx/canvas_paint_mac.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 21 #import "ui/gfx/mac/coordinate_conversion.h" | 23 #import "ui/gfx/mac/coordinate_conversion.h" |
| 22 #include "ui/gfx/path.h" | 24 #include "ui/gfx/path.h" |
| 23 #import "ui/gfx/path_mac.h" | 25 #import "ui/gfx/path_mac.h" |
| 24 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 26 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 25 #include "ui/strings/grit/ui_strings.h" | 27 #include "ui/strings/grit/ui_strings.h" |
| 28 #import "ui/views/cocoa/bridged_native_widget.h" | |
| 29 #include "ui/views/cocoa/drag_drop_client_mac.h" | |
|
tapted
2016/05/31 11:49:58
nit: import
spqchan
2016/05/31 23:06:12
Done.
| |
| 26 #include "ui/views/controls/menu/menu_config.h" | 30 #include "ui/views/controls/menu/menu_config.h" |
| 27 #include "ui/views/controls/menu/menu_controller.h" | 31 #include "ui/views/controls/menu/menu_controller.h" |
| 28 #include "ui/views/view.h" | 32 #include "ui/views/view.h" |
| 33 #include "ui/views/widget/native_widget_mac.h" | |
| 29 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 30 | 35 |
| 31 using views::MenuController; | 36 using views::MenuController; |
| 32 | 37 |
| 33 namespace { | 38 namespace { |
| 34 | 39 |
| 35 NSString* const kFullKeyboardAccessChangedNotification = | 40 NSString* const kFullKeyboardAccessChangedNotification = |
| 36 @"com.apple.KeyboardUIModeDidChange"; | 41 @"com.apple.KeyboardUIModeDidChange"; |
| 37 | 42 |
| 38 // Returns true if all four corners of |rect| are contained inside |path|. | 43 // Returns true if all four corners of |rect| are contained inside |path|. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to | 223 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to |
| 219 // get something readable. | 224 // get something readable. |
| 220 - (void)handleAction:(int)commandId | 225 - (void)handleAction:(int)commandId |
| 221 keyCode:(ui::KeyboardCode)keyCode | 226 keyCode:(ui::KeyboardCode)keyCode |
| 222 domCode:(ui::DomCode)domCode | 227 domCode:(ui::DomCode)domCode |
| 223 eventFlags:(int)eventFlags; | 228 eventFlags:(int)eventFlags; |
| 224 | 229 |
| 225 // Notification handler invoked when the Full Keyboard Access mode is changed. | 230 // Notification handler invoked when the Full Keyboard Access mode is changed. |
| 226 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; | 231 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; |
| 227 | 232 |
| 233 - (views::DragDropClientMac*)dragDropClient; | |
| 234 | |
| 228 // Menu action handlers. | 235 // Menu action handlers. |
| 229 - (void)undo:(id)sender; | 236 - (void)undo:(id)sender; |
| 230 - (void)redo:(id)sender; | 237 - (void)redo:(id)sender; |
| 231 - (void)cut:(id)sender; | 238 - (void)cut:(id)sender; |
| 232 - (void)copy:(id)sender; | 239 - (void)copy:(id)sender; |
| 233 - (void)paste:(id)sender; | 240 - (void)paste:(id)sender; |
| 234 - (void)selectAll:(id)sender; | 241 - (void)selectAll:(id)sender; |
| 235 | 242 |
| 236 @end | 243 @end |
| 237 | 244 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 266 [[NSDistributedNotificationCenter defaultCenter] | 273 [[NSDistributedNotificationCenter defaultCenter] |
| 267 addObserver:self | 274 addObserver:self |
| 268 selector:@selector(onFullKeyboardAccessModeChanged:) | 275 selector:@selector(onFullKeyboardAccessModeChanged:) |
| 269 name:kFullKeyboardAccessChangedNotification | 276 name:kFullKeyboardAccessChangedNotification |
| 270 object:nil]; | 277 object:nil]; |
| 271 | 278 |
| 272 // Initialize the focus manager with the correct keyboard accessibility | 279 // Initialize the focus manager with the correct keyboard accessibility |
| 273 // setting. | 280 // setting. |
| 274 [self updateFullKeyboardAccess]; | 281 [self updateFullKeyboardAccess]; |
| 275 } | 282 } |
| 283 | |
| 284 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac:: | |
|
tapted
2016/05/31 11:49:57
nit: move this into the if {}
spqchan
2016/05/31 23:06:12
Done.
| |
| 285 SupportedPasteboardTypes()]; | |
| 286 | |
| 276 return self; | 287 return self; |
| 277 } | 288 } |
| 278 | 289 |
| 279 - (void)clearView { | 290 - (void)clearView { |
| 280 textInputClient_ = nullptr; | 291 textInputClient_ = nullptr; |
| 281 hostedView_ = nullptr; | 292 hostedView_ = nullptr; |
| 282 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; | 293 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
| 283 [cursorTrackingArea_.get() clearOwner]; | 294 [cursorTrackingArea_.get() clearOwner]; |
| 284 [self removeTrackingArea:cursorTrackingArea_.get()]; | 295 [self removeTrackingArea:cursorTrackingArea_.get()]; |
| 285 } | 296 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 297 [self mouseEvent:theEvent]; | 308 [self mouseEvent:theEvent]; |
| 298 return; | 309 return; |
| 299 } | 310 } |
| 300 | 311 |
| 301 ui::MouseEvent event(theEvent); | 312 ui::MouseEvent event(theEvent); |
| 302 event.set_location( | 313 event.set_location( |
| 303 MovePointToWindow([theEvent locationInWindow], source, target)); | 314 MovePointToWindow([theEvent locationInWindow], source, target)); |
| 304 hostedView_->GetWidget()->OnMouseEvent(&event); | 315 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 305 } | 316 } |
| 306 | 317 |
| 318 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | |
|
tapted
2016/05/31 11:49:57
nit: these should move down after the other NSView
spqchan
2016/05/31 23:06:12
Done.
| |
| 319 return [self draggingUpdated:sender]; | |
| 320 } | |
| 321 | |
| 322 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | |
| 323 views::DragDropClientMac* client = [self dragDropClient]; | |
| 324 return client ? client->DragUpdate(sender) : ui::DragDropTypes::DRAG_NONE; | |
| 325 } | |
| 326 | |
| 327 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | |
| 328 views::DragDropClientMac* client = [self dragDropClient]; | |
| 329 if (client) | |
| 330 return client->Drop(sender) != NSDragOperationNone; | |
| 331 | |
| 332 return NO; | |
|
tapted
2016/05/31 11:49:57
nit: we can do just
return client && client->Drop
spqchan
2016/05/31 23:06:12
Done.
| |
| 333 } | |
| 334 | |
| 307 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { | 335 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { |
| 308 DCHECK(hostedView_); | 336 DCHECK(hostedView_); |
| 309 base::string16 newTooltipText; | 337 base::string16 newTooltipText; |
| 310 | 338 |
| 311 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); | 339 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); |
| 312 if (view) { | 340 if (view) { |
| 313 gfx::Point viewPoint = locationInContent; | 341 gfx::Point viewPoint = locationInContent; |
| 314 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); | 342 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); |
| 315 if (!view->GetTooltipText(viewPoint, &newTooltipText)) | 343 if (!view->GetTooltipText(viewPoint, &newTooltipText)) |
| 316 DCHECK(newTooltipText.empty()); | 344 DCHECK(newTooltipText.empty()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); | 417 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); |
| 390 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); | 418 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); |
| 391 } | 419 } |
| 392 | 420 |
| 393 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { | 421 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { |
| 394 DCHECK([[notification name] | 422 DCHECK([[notification name] |
| 395 isEqualToString:kFullKeyboardAccessChangedNotification]); | 423 isEqualToString:kFullKeyboardAccessChangedNotification]); |
| 396 [self updateFullKeyboardAccess]; | 424 [self updateFullKeyboardAccess]; |
| 397 } | 425 } |
| 398 | 426 |
| 427 - (views::DragDropClientMac*)dragDropClient { | |
| 428 views::BridgedNativeWidget* bridge = | |
| 429 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); | |
| 430 return bridge ? bridge->drag_drop_client() : nullptr; | |
| 431 } | |
| 432 | |
| 399 - (void)undo:(id)sender { | 433 - (void)undo:(id)sender { |
| 400 // This DCHECK is more strict than a similar check in handleAction:. It can be | 434 // This DCHECK is more strict than a similar check in handleAction:. It can be |
| 401 // done here because the actors sending these actions should be calling | 435 // done here because the actors sending these actions should be calling |
| 402 // validateUserInterfaceItem: before enabling UI that allows these messages to | 436 // validateUserInterfaceItem: before enabling UI that allows these messages to |
| 403 // be sent. Checking it here would be too late to provide correct UI feedback | 437 // be sent. Checking it here would be too late to provide correct UI feedback |
| 404 // (e.g. there will be no "beep"). | 438 // (e.g. there will be no "beep"). |
| 405 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); | 439 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); |
| 406 [self handleAction:IDS_APP_UNDO | 440 [self handleAction:IDS_APP_UNDO |
| 407 keyCode:ui::VKEY_Z | 441 keyCode:ui::VKEY_Z |
| 408 domCode:ui::DomCode::US_Z | 442 domCode:ui::DomCode::US_Z |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 return @[ hostedView_->GetNativeViewAccessible() ]; | 1218 return @[ hostedView_->GetNativeViewAccessible() ]; |
| 1185 } | 1219 } |
| 1186 | 1220 |
| 1187 return [super accessibilityAttributeValue:attribute]; | 1221 return [super accessibilityAttributeValue:attribute]; |
| 1188 } | 1222 } |
| 1189 | 1223 |
| 1190 - (id)accessibilityHitTest:(NSPoint)point { | 1224 - (id)accessibilityHitTest:(NSPoint)point { |
| 1191 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1225 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1192 } | 1226 } |
| 1193 | 1227 |
| 1228 // NSDraggingSource protocol implementation | |
|
tapted
2016/05/31 11:49:57
nit: move this up, to come after NSUserInterfaceVa
spqchan
2016/05/31 23:06:12
Done.
| |
| 1229 | |
| 1230 - (NSDragOperation)draggingSession:(NSDraggingSession*)session | |
| 1231 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { | |
| 1232 return NSDragOperationEvery; | |
| 1233 } | |
| 1234 | |
| 1235 - (void)draggingSession:(NSDraggingSession*)session | |
| 1236 endedAtPoint:(NSPoint)screenPoint | |
| 1237 operation:(NSDragOperation)operation { | |
| 1238 views::DragDropClientMac* client = [self dragDropClient]; | |
| 1239 if (client) | |
| 1240 client->EndDrag(); | |
| 1241 } | |
| 1242 | |
| 1194 @end | 1243 @end |
| OLD | NEW |