Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Side by Side Diff: ui/views/cocoa/bridged_content_view.mm

Issue 1964283002: MacViews: Implemented Drag & Drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix for dcheng Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Returns the native Widget's drag drop client. Possibly null.
234 - (views::DragDropClientMac*)dragDropClient;
235
228 // Menu action handlers. 236 // Menu action handlers.
229 - (void)undo:(id)sender; 237 - (void)undo:(id)sender;
230 - (void)redo:(id)sender; 238 - (void)redo:(id)sender;
231 - (void)cut:(id)sender; 239 - (void)cut:(id)sender;
232 - (void)copy:(id)sender; 240 - (void)copy:(id)sender;
233 - (void)paste:(id)sender; 241 - (void)paste:(id)sender;
234 - (void)selectAll:(id)sender; 242 - (void)selectAll:(id)sender;
235 243
236 @end 244 @end
237 245
(...skipping 27 matching lines...) Expand all
265 // Get notified whenever Full Keyboard Access mode is changed. 273 // Get notified whenever Full Keyboard Access mode is changed.
266 [[NSDistributedNotificationCenter defaultCenter] 274 [[NSDistributedNotificationCenter defaultCenter]
267 addObserver:self 275 addObserver:self
268 selector:@selector(onFullKeyboardAccessModeChanged:) 276 selector:@selector(onFullKeyboardAccessModeChanged:)
269 name:kFullKeyboardAccessChangedNotification 277 name:kFullKeyboardAccessChangedNotification
270 object:nil]; 278 object:nil];
271 279
272 // Initialize the focus manager with the correct keyboard accessibility 280 // Initialize the focus manager with the correct keyboard accessibility
273 // setting. 281 // setting.
274 [self updateFullKeyboardAccess]; 282 [self updateFullKeyboardAccess];
283 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac::
284 SupportedPasteboardTypes()];
275 } 285 }
276 return self; 286 return self;
277 } 287 }
278 288
279 - (void)clearView { 289 - (void)clearView {
280 textInputClient_ = nullptr; 290 textInputClient_ = nullptr;
281 hostedView_ = nullptr; 291 hostedView_ = nullptr;
282 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; 292 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
283 [cursorTrackingArea_.get() clearOwner]; 293 [cursorTrackingArea_.get() clearOwner];
284 [self removeTrackingArea:cursorTrackingArea_.get()]; 294 [self removeTrackingArea:cursorTrackingArea_.get()];
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); 399 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags);
390 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); 400 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event);
391 } 401 }
392 402
393 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { 403 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification {
394 DCHECK([[notification name] 404 DCHECK([[notification name]
395 isEqualToString:kFullKeyboardAccessChangedNotification]); 405 isEqualToString:kFullKeyboardAccessChangedNotification]);
396 [self updateFullKeyboardAccess]; 406 [self updateFullKeyboardAccess];
397 } 407 }
398 408
409 - (views::DragDropClientMac*)dragDropClient {
410 views::BridgedNativeWidget* bridge =
411 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]);
412 return bridge ? bridge->drag_drop_client() : nullptr;
413 }
414
399 - (void)undo:(id)sender { 415 - (void)undo:(id)sender {
400 // This DCHECK is more strict than a similar check in handleAction:. It can be 416 // 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 417 // done here because the actors sending these actions should be calling
402 // validateUserInterfaceItem: before enabling UI that allows these messages to 418 // validateUserInterfaceItem: before enabling UI that allows these messages to
403 // be sent. Checking it here would be too late to provide correct UI feedback 419 // be sent. Checking it here would be too late to provide correct UI feedback
404 // (e.g. there will be no "beep"). 420 // (e.g. there will be no "beep").
405 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); 421 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO));
406 [self handleAction:IDS_APP_UNDO 422 [self handleAction:IDS_APP_UNDO
407 keyCode:ui::VKEY_Z 423 keyCode:ui::VKEY_Z
408 domCode:ui::DomCode::US_Z 424 domCode:ui::DomCode::US_Z
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 ui::CanvasPainter(&canvas, 1.f).context()); 594 ui::CanvasPainter(&canvas, 1.f).context());
579 } 595 }
580 596
581 // To maximize consistency with the Cocoa browser (mac_views_browser=0), accept 597 // 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 598 // 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. 599 // will allow the event to be processed, rather than merely activate the window.
584 - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent { 600 - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
585 return YES; 601 return YES;
586 } 602 }
587 603
604 // NSDraggingDestination protocol overrides.
605
606 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
607 return [self draggingUpdated:sender];
608 }
609
610 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
611 views::DragDropClientMac* client = [self dragDropClient];
612 return client ? client->DragUpdate(sender) : ui::DragDropTypes::DRAG_NONE;
613 }
614
615 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
616 views::DragDropClientMac* client = [self dragDropClient];
617 return client && client->Drop(sender) != NSDragOperationNone;
618 }
619
588 - (NSTextInputContext*)inputContext { 620 - (NSTextInputContext*)inputContext {
589 // If the textInputClient_ does not exist, return nil since this view does not 621 // If the textInputClient_ does not exist, return nil since this view does not
590 // conform to NSTextInputClient protocol. 622 // conform to NSTextInputClient protocol.
591 if (!textInputClient_) 623 if (!textInputClient_)
592 return nil; 624 return nil;
593 625
594 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the 626 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the
595 // input context, return nil. This ensures the action message is sent to 627 // input context, return nil. This ensures the action message is sent to
596 // the view, rather than any NSTextInputClient a subview has installed. 628 // the view, rather than any NSTextInputClient a subview has installed.
597 MenuController* menuController = MenuController::GetActiveInstance(); 629 MenuController* menuController = MenuController::GetActiveInstance();
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 if (action == @selector(copy:)) 1202 if (action == @selector(copy:))
1171 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY); 1203 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY);
1172 if (action == @selector(paste:)) 1204 if (action == @selector(paste:))
1173 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE); 1205 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE);
1174 if (action == @selector(selectAll:)) 1206 if (action == @selector(selectAll:))
1175 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL); 1207 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL);
1176 1208
1177 return NO; 1209 return NO;
1178 } 1210 }
1179 1211
1212 // NSDraggingSource protocol implementation.
1213
1214 - (NSDragOperation)draggingSession:(NSDraggingSession*)session
1215 sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
1216 return NSDragOperationEvery;
1217 }
1218
1219 - (void)draggingSession:(NSDraggingSession*)session
1220 endedAtPoint:(NSPoint)screenPoint
1221 operation:(NSDragOperation)operation {
1222 views::DragDropClientMac* client = [self dragDropClient];
1223 if (client)
1224 client->EndDrag();
1225 }
1226
1180 // NSAccessibility informal protocol implementation. 1227 // NSAccessibility informal protocol implementation.
1181 1228
1182 - (id)accessibilityAttributeValue:(NSString*)attribute { 1229 - (id)accessibilityAttributeValue:(NSString*)attribute {
1183 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { 1230 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
1184 return @[ hostedView_->GetNativeViewAccessible() ]; 1231 return @[ hostedView_->GetNativeViewAccessible() ];
1185 } 1232 }
1186 1233
1187 return [super accessibilityAttributeValue:attribute]; 1234 return [super accessibilityAttributeValue:attribute];
1188 } 1235 }
1189 1236
1190 - (id)accessibilityHitTest:(NSPoint)point { 1237 - (id)accessibilityHitTest:(NSPoint)point {
1191 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1238 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1192 } 1239 }
1193 1240
1194 @end 1241 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698