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

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: Forgot to add the test Created 4 years, 7 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/os_exchange_data_provider_mac.h"
13 #include "ui/base/ime/input_method.h" 14 #include "ui/base/ime/input_method.h"
14 #include "ui/base/ime/text_input_client.h" 15 #include "ui/base/ime/text_input_client.h"
15 #include "ui/compositor/canvas_painter.h" 16 #include "ui/compositor/canvas_painter.h"
16 #import "ui/events/cocoa/cocoa_event_utils.h" 17 #import "ui/events/cocoa/cocoa_event_utils.h"
17 #include "ui/events/keycodes/dom/dom_code.h" 18 #include "ui/events/keycodes/dom/dom_code.h"
18 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 19 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
19 #include "ui/gfx/canvas_paint_mac.h" 20 #include "ui/gfx/canvas_paint_mac.h"
20 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
21 #import "ui/gfx/mac/coordinate_conversion.h" 22 #import "ui/gfx/mac/coordinate_conversion.h"
22 #include "ui/gfx/path.h" 23 #include "ui/gfx/path.h"
23 #import "ui/gfx/path_mac.h" 24 #import "ui/gfx/path_mac.h"
24 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 25 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
25 #include "ui/strings/grit/ui_strings.h" 26 #include "ui/strings/grit/ui_strings.h"
27 #import "ui/views/cocoa/bridged_native_widget.h"
28 #include "ui/views/cocoa/drag_drop_client_mac.h"
26 #include "ui/views/controls/menu/menu_config.h" 29 #include "ui/views/controls/menu/menu_config.h"
27 #include "ui/views/controls/menu/menu_controller.h" 30 #include "ui/views/controls/menu/menu_controller.h"
28 #include "ui/views/view.h" 31 #include "ui/views/view.h"
32 #include "ui/views/widget/native_widget_mac.h"
29 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
30 34
31 using views::MenuController; 35 using views::MenuController;
32 36
33 namespace { 37 namespace {
34 38
35 NSString* const kFullKeyboardAccessChangedNotification = 39 NSString* const kFullKeyboardAccessChangedNotification =
36 @"com.apple.KeyboardUIModeDidChange"; 40 @"com.apple.KeyboardUIModeDidChange";
37 41
38 // Returns true if all four corners of |rect| are contained inside |path|. 42 // Returns true if all four corners of |rect| are contained inside |path|.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to 188 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to
185 // get something readable. 189 // get something readable.
186 - (void)handleAction:(int)commandId 190 - (void)handleAction:(int)commandId
187 keyCode:(ui::KeyboardCode)keyCode 191 keyCode:(ui::KeyboardCode)keyCode
188 domCode:(ui::DomCode)domCode 192 domCode:(ui::DomCode)domCode
189 eventFlags:(int)eventFlags; 193 eventFlags:(int)eventFlags;
190 194
191 // Notification handler invoked when the Full Keyboard Access mode is changed. 195 // Notification handler invoked when the Full Keyboard Access mode is changed.
192 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; 196 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification;
193 197
198 - (views::DragDropClientMac*)dragDropClient;
199
194 // Menu action handlers. 200 // Menu action handlers.
195 - (void)undo:(id)sender; 201 - (void)undo:(id)sender;
196 - (void)redo:(id)sender; 202 - (void)redo:(id)sender;
197 - (void)cut:(id)sender; 203 - (void)cut:(id)sender;
198 - (void)copy:(id)sender; 204 - (void)copy:(id)sender;
199 - (void)paste:(id)sender; 205 - (void)paste:(id)sender;
200 - (void)selectAll:(id)sender; 206 - (void)selectAll:(id)sender;
201 207
202 @end 208 @end
203 209
(...skipping 28 matching lines...) Expand all
232 [[NSDistributedNotificationCenter defaultCenter] 238 [[NSDistributedNotificationCenter defaultCenter]
233 addObserver:self 239 addObserver:self
234 selector:@selector(onFullKeyboardAccessModeChanged:) 240 selector:@selector(onFullKeyboardAccessModeChanged:)
235 name:kFullKeyboardAccessChangedNotification 241 name:kFullKeyboardAccessChangedNotification
236 object:nil]; 242 object:nil];
237 243
238 // Initialize the focus manager with the correct keyboard accessibility 244 // Initialize the focus manager with the correct keyboard accessibility
239 // setting. 245 // setting.
240 [self updateFullKeyboardAccess]; 246 [self updateFullKeyboardAccess];
241 } 247 }
248
249 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac::
250 SupportedPasteboardTypes()];
251
242 return self; 252 return self;
243 } 253 }
244 254
245 - (void)clearView { 255 - (void)clearView {
246 textInputClient_ = nullptr; 256 textInputClient_ = nullptr;
247 hostedView_ = nullptr; 257 hostedView_ = nullptr;
248 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; 258 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
249 [cursorTrackingArea_.get() clearOwner]; 259 [cursorTrackingArea_.get() clearOwner];
250 [self removeTrackingArea:cursorTrackingArea_.get()]; 260 [self removeTrackingArea:cursorTrackingArea_.get()];
251 } 261 }
(...skipping 11 matching lines...) Expand all
263 [self mouseEvent:theEvent]; 273 [self mouseEvent:theEvent];
264 return; 274 return;
265 } 275 }
266 276
267 ui::MouseEvent event(theEvent); 277 ui::MouseEvent event(theEvent);
268 event.set_location( 278 event.set_location(
269 MovePointToWindow([theEvent locationInWindow], source, target)); 279 MovePointToWindow([theEvent locationInWindow], source, target));
270 hostedView_->GetWidget()->OnMouseEvent(&event); 280 hostedView_->GetWidget()->OnMouseEvent(&event);
271 } 281 }
272 282
283 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
284 return [self dragDropClient]->DragUpdate(sender);
tapted 2016/05/24 08:06:01 [self dragDropClient] needs to return null under s
spqchan 2016/05/26 01:56:53 Done.
285 }
286
287 - (NSDragOperation)draggingUpdated:(id)sender {
288 return [self dragDropClient]->DragUpdate(sender);
289 }
290
291 - (void)draggingEnded:(id)sender {
292 [self dragDropClient]->EndDrag();
293 }
294
295 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
296 return [self dragDropClient]->Drop(sender) != NSDragOperationNone;
297 }
298
273 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { 299 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent {
274 DCHECK(hostedView_); 300 DCHECK(hostedView_);
275 base::string16 newTooltipText; 301 base::string16 newTooltipText;
276 302
277 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); 303 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent);
278 if (view) { 304 if (view) {
279 gfx::Point viewPoint = locationInContent; 305 gfx::Point viewPoint = locationInContent;
280 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); 306 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint);
281 if (!view->GetTooltipText(viewPoint, &newTooltipText)) 307 if (!view->GetTooltipText(viewPoint, &newTooltipText))
282 DCHECK(newTooltipText.empty()); 308 DCHECK(newTooltipText.empty());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); 381 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags);
356 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); 382 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event);
357 } 383 }
358 384
359 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { 385 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification {
360 DCHECK([[notification name] 386 DCHECK([[notification name]
361 isEqualToString:kFullKeyboardAccessChangedNotification]); 387 isEqualToString:kFullKeyboardAccessChangedNotification]);
362 [self updateFullKeyboardAccess]; 388 [self updateFullKeyboardAccess];
363 } 389 }
364 390
391 - (views::DragDropClientMac*)dragDropClient {
392 return views::NativeWidgetMac::GetBridgeForNativeWindow([self window])
tapted 2016/05/24 08:06:00 GetBridgeForNativeWindow can return null. Annoying
spqchan 2016/05/26 01:56:53 Done.
393 ->drag_drop_client();
394 }
395
365 - (void)undo:(id)sender { 396 - (void)undo:(id)sender {
366 // This DCHECK is more strict than a similar check in handleAction:. It can be 397 // This DCHECK is more strict than a similar check in handleAction:. It can be
367 // done here because the actors sending these actions should be calling 398 // done here because the actors sending these actions should be calling
368 // validateUserInterfaceItem: before enabling UI that allows these messages to 399 // validateUserInterfaceItem: before enabling UI that allows these messages to
369 // be sent. Checking it here would be too late to provide correct UI feedback 400 // be sent. Checking it here would be too late to provide correct UI feedback
370 // (e.g. there will be no "beep"). 401 // (e.g. there will be no "beep").
371 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); 402 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO));
372 [self handleAction:IDS_APP_UNDO 403 [self handleAction:IDS_APP_UNDO
373 keyCode:ui::VKEY_Z 404 keyCode:ui::VKEY_Z
374 domCode:ui::DomCode::US_Z 405 domCode:ui::DomCode::US_Z
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 } 1017 }
987 1018
988 return [super accessibilityAttributeValue:attribute]; 1019 return [super accessibilityAttributeValue:attribute];
989 } 1020 }
990 1021
991 - (id)accessibilityHitTest:(NSPoint)point { 1022 - (id)accessibilityHitTest:(NSPoint)point {
992 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1023 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
993 } 1024 }
994 1025
995 @end 1026 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698