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" | |
| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to | 189 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to |
| 185 // get something readable. | 190 // get something readable. |
| 186 - (void)handleAction:(int)commandId | 191 - (void)handleAction:(int)commandId |
| 187 keyCode:(ui::KeyboardCode)keyCode | 192 keyCode:(ui::KeyboardCode)keyCode |
| 188 domCode:(ui::DomCode)domCode | 193 domCode:(ui::DomCode)domCode |
| 189 eventFlags:(int)eventFlags; | 194 eventFlags:(int)eventFlags; |
| 190 | 195 |
| 191 // Notification handler invoked when the Full Keyboard Access mode is changed. | 196 // Notification handler invoked when the Full Keyboard Access mode is changed. |
| 192 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; | 197 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification; |
| 193 | 198 |
| 199 - (views::DragDropClientMac*)dragDropClient; | |
| 200 | |
| 194 // Menu action handlers. | 201 // Menu action handlers. |
| 195 - (void)undo:(id)sender; | 202 - (void)undo:(id)sender; |
| 196 - (void)redo:(id)sender; | 203 - (void)redo:(id)sender; |
| 197 - (void)cut:(id)sender; | 204 - (void)cut:(id)sender; |
| 198 - (void)copy:(id)sender; | 205 - (void)copy:(id)sender; |
| 199 - (void)paste:(id)sender; | 206 - (void)paste:(id)sender; |
| 200 - (void)selectAll:(id)sender; | 207 - (void)selectAll:(id)sender; |
| 201 | 208 |
| 202 @end | 209 @end |
| 203 | 210 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 232 [[NSDistributedNotificationCenter defaultCenter] | 239 [[NSDistributedNotificationCenter defaultCenter] |
| 233 addObserver:self | 240 addObserver:self |
| 234 selector:@selector(onFullKeyboardAccessModeChanged:) | 241 selector:@selector(onFullKeyboardAccessModeChanged:) |
| 235 name:kFullKeyboardAccessChangedNotification | 242 name:kFullKeyboardAccessChangedNotification |
| 236 object:nil]; | 243 object:nil]; |
| 237 | 244 |
| 238 // Initialize the focus manager with the correct keyboard accessibility | 245 // Initialize the focus manager with the correct keyboard accessibility |
| 239 // setting. | 246 // setting. |
| 240 [self updateFullKeyboardAccess]; | 247 [self updateFullKeyboardAccess]; |
| 241 } | 248 } |
| 249 | |
| 250 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac:: | |
| 251 SupportedPasteboardTypes()]; | |
| 252 | |
| 242 return self; | 253 return self; |
| 243 } | 254 } |
| 244 | 255 |
| 245 - (void)clearView { | 256 - (void)clearView { |
| 246 textInputClient_ = nullptr; | 257 textInputClient_ = nullptr; |
| 247 hostedView_ = nullptr; | 258 hostedView_ = nullptr; |
| 248 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; | 259 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
| 249 [cursorTrackingArea_.get() clearOwner]; | 260 [cursorTrackingArea_.get() clearOwner]; |
| 250 [self removeTrackingArea:cursorTrackingArea_.get()]; | 261 [self removeTrackingArea:cursorTrackingArea_.get()]; |
| 251 } | 262 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 263 [self mouseEvent:theEvent]; | 274 [self mouseEvent:theEvent]; |
| 264 return; | 275 return; |
| 265 } | 276 } |
| 266 | 277 |
| 267 ui::MouseEvent event(theEvent); | 278 ui::MouseEvent event(theEvent); |
| 268 event.set_location( | 279 event.set_location( |
| 269 MovePointToWindow([theEvent locationInWindow], source, target)); | 280 MovePointToWindow([theEvent locationInWindow], source, target)); |
| 270 hostedView_->GetWidget()->OnMouseEvent(&event); | 281 hostedView_->GetWidget()->OnMouseEvent(&event); |
| 271 } | 282 } |
| 272 | 283 |
| 284 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | |
| 285 return [self draggingUpdated:sender]; | |
| 286 } | |
| 287 | |
| 288 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | |
| 289 views::DragDropClientMac* client = [self dragDropClient]; | |
| 290 return client ? client->DragUpdate(sender) : ui::DragDropTypes::DRAG_NONE; | |
| 291 } | |
| 292 | |
| 293 - (void)draggingEnded:(id<NSDraggingInfo>)sender { | |
| 294 views::DragDropClientMac* client = [self dragDropClient]; | |
| 295 if (client) | |
| 296 client->EndDrag(); | |
| 297 } | |
| 298 | |
| 299 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | |
| 300 views::DragDropClientMac* client = [self dragDropClient]; | |
| 301 if (client) | |
| 302 return client->Drop(sender) != NSDragOperationNone; | |
| 303 | |
| 304 return false; | |
|
tapted
2016/05/26 12:31:42
nit: false -> NO
spqchan
2016/05/27 23:25:48
Done.
| |
| 305 } | |
| 306 | |
| 273 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { | 307 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { |
| 274 DCHECK(hostedView_); | 308 DCHECK(hostedView_); |
| 275 base::string16 newTooltipText; | 309 base::string16 newTooltipText; |
| 276 | 310 |
| 277 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); | 311 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); |
| 278 if (view) { | 312 if (view) { |
| 279 gfx::Point viewPoint = locationInContent; | 313 gfx::Point viewPoint = locationInContent; |
| 280 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); | 314 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); |
| 281 if (!view->GetTooltipText(viewPoint, &newTooltipText)) | 315 if (!view->GetTooltipText(viewPoint, &newTooltipText)) |
| 282 DCHECK(newTooltipText.empty()); | 316 DCHECK(newTooltipText.empty()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); | 389 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); |
| 356 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); | 390 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(&event); |
| 357 } | 391 } |
| 358 | 392 |
| 359 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { | 393 - (void)onFullKeyboardAccessModeChanged:(NSNotification*)notification { |
| 360 DCHECK([[notification name] | 394 DCHECK([[notification name] |
| 361 isEqualToString:kFullKeyboardAccessChangedNotification]); | 395 isEqualToString:kFullKeyboardAccessChangedNotification]); |
| 362 [self updateFullKeyboardAccess]; | 396 [self updateFullKeyboardAccess]; |
| 363 } | 397 } |
| 364 | 398 |
| 399 - (views::DragDropClientMac*)dragDropClient { | |
| 400 views::BridgedNativeWidget* bridge = | |
| 401 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); | |
| 402 return bridge ? bridge->drag_drop_client() : nullptr; | |
| 403 } | |
| 404 | |
| 365 - (void)undo:(id)sender { | 405 - (void)undo:(id)sender { |
| 366 // This DCHECK is more strict than a similar check in handleAction:. It can be | 406 // 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 | 407 // done here because the actors sending these actions should be calling |
| 368 // validateUserInterfaceItem: before enabling UI that allows these messages to | 408 // validateUserInterfaceItem: before enabling UI that allows these messages to |
| 369 // be sent. Checking it here would be too late to provide correct UI feedback | 409 // be sent. Checking it here would be too late to provide correct UI feedback |
| 370 // (e.g. there will be no "beep"). | 410 // (e.g. there will be no "beep"). |
| 371 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); | 411 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO)); |
| 372 [self handleAction:IDS_APP_UNDO | 412 [self handleAction:IDS_APP_UNDO |
| 373 keyCode:ui::VKEY_Z | 413 keyCode:ui::VKEY_Z |
| 374 domCode:ui::DomCode::US_Z | 414 domCode:ui::DomCode::US_Z |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 } | 1026 } |
| 987 | 1027 |
| 988 return [super accessibilityAttributeValue:attribute]; | 1028 return [super accessibilityAttributeValue:attribute]; |
| 989 } | 1029 } |
| 990 | 1030 |
| 991 - (id)accessibilityHitTest:(NSPoint)point { | 1031 - (id)accessibilityHitTest:(NSPoint)point { |
| 992 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1032 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 993 } | 1033 } |
| 994 | 1034 |
| 995 @end | 1035 @end |
| OLD | NEW |