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 #import "ui/views/cocoa/drag_drop_client_mac.h" | |
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 27 matching lines...) Expand all Loading... | |
265 // Get notified whenever Full Keyboard Access mode is changed. | 272 // Get notified whenever Full Keyboard Access mode is changed. |
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]; |
282 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac:: | |
283 SupportedPasteboardTypes()]; | |
275 } | 284 } |
276 return self; | 285 return self; |
277 } | 286 } |
278 | 287 |
279 - (void)clearView { | 288 - (void)clearView { |
280 textInputClient_ = nullptr; | 289 textInputClient_ = nullptr; |
281 hostedView_ = nullptr; | 290 hostedView_ = nullptr; |
282 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; | 291 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
283 [cursorTrackingArea_.get() clearOwner]; | 292 [cursorTrackingArea_.get() clearOwner]; |
284 [self removeTrackingArea:cursorTrackingArea_.get()]; | 293 [self removeTrackingArea:cursorTrackingArea_.get()]; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); | 398 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); |
390 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); | 399 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); |
391 } | 400 } |
392 | 401 |
393 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { | 402 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { |
394 DCHECK([[notification name] | 403 DCHECK([[notification name] |
395 isEqualToString:kFullKeyboardAccessChangedNotification]); | 404 isEqualToString:kFullKeyboardAccessChangedNotification]); |
396 [self updateFullKeyboardAccess]; | 405 [self updateFullKeyboardAccess]; |
397 } | 406 } |
398 | 407 |
408 - (views::DragDropClientMac*)dragDropClient { | |
409 views::BridgedNativeWidget* bridge = | |
410 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); | |
411 return bridge ? bridge->drag_drop_client() : nullptr; | |
412 } | |
413 | |
399 - (void)undo:(id)sender { | 414 - (void)undo:(id)sender { |
400 // This DCHECK is more strict than a similar check in handleAction:. It can be | 415 // 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 | 416 // done here because the actors sending these actions should be calling |
402 // validateUserInterfaceItem: before enabling UI that allows these messages to | 417 // validateUserInterfaceItem: before enabling UI that allows these messages to |
403 // be sent. Checking it here would be too late to provide correct UI feedback | 418 // be sent. Checking it here would be too late to provide correct UI feedback |
404 // (e.g. there will be no "beep"). | 419 // (e.g. there will be no "beep"). |
405 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); | 420 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); |
406 [self handleAction:IDS_APP_UNDO | 421 [self handleAction:IDS_APP_UNDO |
407 keyCode:ui::VKEY_Z | 422 keyCode:ui::VKEY_Z |
408 domCode:ui::DomCode::US_Z | 423 domCode:ui::DomCode::US_Z |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 ui::CanvasPainter(&canvas, 1.f).context()); | 593 ui::CanvasPainter(&canvas, 1.f).context()); |
579 } | 594 } |
580 | 595 |
581 // To maximize consistency with the Cocoa browser (mac_views_browser=0), accept | 596 // To maximize consistency with the Cocoa browser (mac_views_browser=0), accept |
582 // mouse clicks immediately so that clicking on Chrome from an inactive window | 597 // mouse clicks immediately so that clicking on Chrome from an inactive window |
583 // will allow the event to be processed, rather than merely activate the window. | 598 // will allow the event to be processed, rather than merely activate the window. |
584 - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent { | 599 - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent { |
585 return YES; | 600 return YES; |
586 } | 601 } |
587 | 602 |
603 // NSDraggingDestination protocol overrides: | |
tapted
2016/06/01 01:57:01
nit: full stop instead of colon
spqchan
2016/06/01 19:09:28
Done.
| |
604 | |
605 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | |
606 return [self draggingUpdated:sender]; | |
607 } | |
608 | |
609 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | |
610 views::DragDropClientMac* client = [self dragDropClient]; | |
611 return client ? client->DragUpdate(sender) : ui::DragDropTypes::DRAG_NONE; | |
612 } | |
613 | |
614 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | |
615 views::DragDropClientMac* client = [self dragDropClient]; | |
616 return client && client->Drop(sender) != NSDragOperationNone; | |
617 } | |
618 | |
588 - (NSTextInputContext*)inputContext { | 619 - (NSTextInputContext*)inputContext { |
589 // If the textInputClient_ does not exist, return nil since this view does not | 620 // If the textInputClient_ does not exist, return nil since this view does not |
590 // conform to NSTextInputClient protocol. | 621 // conform to NSTextInputClient protocol. |
591 if (!textInputClient_) | 622 if (!textInputClient_) |
592 return nil; | 623 return nil; |
593 | 624 |
594 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the | 625 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the |
595 // input context, return nil. This ensures the action message is sent to | 626 // input context, return nil. This ensures the action message is sent to |
596 // the view, rather than any NSTextInputClient a subview has installed. | 627 // the view, rather than any NSTextInputClient a subview has installed. |
597 MenuController* menuController = MenuController::GetActiveInstance(); | 628 MenuController* menuController = MenuController::GetActiveInstance(); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1170 if (action == @selector(copy:)) | 1201 if (action == @selector(copy:)) |
1171 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY); | 1202 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY); |
1172 if (action == @selector(paste:)) | 1203 if (action == @selector(paste:)) |
1173 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE); | 1204 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE); |
1174 if (action == @selector(selectAll:)) | 1205 if (action == @selector(selectAll:)) |
1175 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL); | 1206 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL); |
1176 | 1207 |
1177 return NO; | 1208 return NO; |
1178 } | 1209 } |
1179 | 1210 |
1211 // NSDraggingSource protocol implementation | |
tapted
2016/06/01 01:57:00
nit: full stop at end
spqchan
2016/06/01 19:09:28
Done.
| |
1212 | |
1213 - (NSDragOperation)draggingSession:(NSDraggingSession*)session | |
1214 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { | |
1215 return NSDragOperationEvery; | |
1216 } | |
1217 | |
1218 - (void)draggingSession:(NSDraggingSession*)session | |
1219 endedAtPoint:(NSPoint)screenPoint | |
1220 operation:(NSDragOperation)operation { | |
1221 views::DragDropClientMac* client = [self dragDropClient]; | |
1222 if (client) | |
1223 client->EndDrag(); | |
1224 } | |
1225 | |
1180 // NSAccessibility informal protocol implementation. | 1226 // NSAccessibility informal protocol implementation. |
1181 | 1227 |
1182 - (id)accessibilityAttributeValue:(NSString*)attribute { | 1228 - (id)accessibilityAttributeValue:(NSString*)attribute { |
1183 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { | 1229 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { |
1184 return @[ hostedView_->GetNativeViewAccessible() ]; | 1230 return @[ hostedView_->GetNativeViewAccessible() ]; |
1185 } | 1231 } |
1186 | 1232 |
1187 return [super accessibilityAttributeValue:attribute]; | 1233 return [super accessibilityAttributeValue:attribute]; |
1188 } | 1234 } |
1189 | 1235 |
1190 - (id)accessibilityHitTest:(NSPoint)point { | 1236 - (id)accessibilityHitTest:(NSPoint)point { |
1191 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1237 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
1192 } | 1238 } |
1193 | 1239 |
1194 @end | 1240 @end |
OLD | NEW |