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 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 if (attribute.strike) | 240 if (attribute.strike) |
| 241 attrs[NSStrikethroughStyleAttributeName] = line_style; | 241 attrs[NSStrikethroughStyleAttributeName] = line_style; |
| 242 | 242 |
| 243 [str setAttributes:attrs range:range]; | 243 [str setAttributes:attrs range:range]; |
| 244 } | 244 } |
| 245 | 245 |
| 246 [str endEditing]; | 246 [str endEditing]; |
| 247 return str.autorelease(); | 247 return str.autorelease(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { | |
| 251 if (action == @selector(undo:)) | |
| 252 return ui::TextEditCommand::UNDO; | |
| 253 if (action == @selector(redo:)) | |
| 254 return ui::TextEditCommand::REDO; | |
| 255 if (action == @selector(cut:)) | |
| 256 return ui::TextEditCommand::CUT; | |
| 257 if (action == @selector(copy:)) | |
| 258 return ui::TextEditCommand::COPY; | |
| 259 if (action == @selector(paste:)) | |
| 260 return ui::TextEditCommand::PASTE; | |
| 261 if (action == @selector(selectAll:)) | |
| 262 return ui::TextEditCommand::SELECT_ALL; | |
| 263 return ui::TextEditCommand::INVALID_COMMAND; | |
| 264 } | |
| 265 | |
| 250 } // namespace | 266 } // namespace |
| 251 | 267 |
| 252 @interface BridgedContentView () | 268 @interface BridgedContentView () |
| 253 | 269 |
| 254 // Returns the active menu controller corresponding to |hostedView_|, | 270 // Returns the active menu controller corresponding to |hostedView_|, |
| 255 // nil otherwise. | 271 // nil otherwise. |
| 256 - (MenuController*)activeMenuController; | 272 - (MenuController*)activeMenuController; |
| 257 | 273 |
| 258 // Passes |event| to the InputMethod for dispatch. | 274 // Passes |event| to the InputMethod for dispatch. |
| 259 - (void)handleKeyEvent:(ui::KeyEvent*)event; | 275 - (void)handleKeyEvent:(ui::KeyEvent*)event; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 } | 529 } |
| 514 } | 530 } |
| 515 | 531 |
| 516 - (views::DragDropClientMac*)dragDropClient { | 532 - (views::DragDropClientMac*)dragDropClient { |
| 517 views::BridgedNativeWidget* bridge = | 533 views::BridgedNativeWidget* bridge = |
| 518 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); | 534 views::NativeWidgetMac::GetBridgeForNativeWindow([self window]); |
| 519 return bridge ? bridge->drag_drop_client() : nullptr; | 535 return bridge ? bridge->drag_drop_client() : nullptr; |
| 520 } | 536 } |
| 521 | 537 |
| 522 - (void)undo:(id)sender { | 538 - (void)undo:(id)sender { |
| 523 // This DCHECK is more strict than a similar check in handleAction:. It can be | |
|
msw
2016/11/09 18:32:52
Someone more familiar with Mac should review this
karandeepb
2016/11/15 10:54:31
Yeah I'll get Trent to review this.
| |
| 524 // done here because the actors sending these actions should be calling | |
| 525 // validateUserInterfaceItem: before enabling UI that allows these messages to | |
| 526 // be sent. Checking it here would be too late to provide correct UI feedback | |
| 527 // (e.g. there will be no "beep"). | |
| 528 DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::UNDO)); | |
| 529 [self handleAction:ui::TextEditCommand::UNDO | 539 [self handleAction:ui::TextEditCommand::UNDO |
| 530 keyCode:ui::VKEY_Z | 540 keyCode:ui::VKEY_Z |
| 531 domCode:ui::DomCode::US_Z | 541 domCode:ui::DomCode::US_Z |
| 532 eventFlags:ui::EF_CONTROL_DOWN]; | 542 eventFlags:ui::EF_CONTROL_DOWN]; |
| 533 } | 543 } |
| 534 | 544 |
| 535 - (void)redo:(id)sender { | 545 - (void)redo:(id)sender { |
| 536 DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::REDO)); | |
| 537 [self handleAction:ui::TextEditCommand::REDO | 546 [self handleAction:ui::TextEditCommand::REDO |
| 538 keyCode:ui::VKEY_Z | 547 keyCode:ui::VKEY_Z |
| 539 domCode:ui::DomCode::US_Z | 548 domCode:ui::DomCode::US_Z |
| 540 eventFlags:ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN]; | 549 eventFlags:ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN]; |
| 541 } | 550 } |
| 542 | 551 |
| 543 - (void)cut:(id)sender { | 552 - (void)cut:(id)sender { |
| 544 DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::CUT)); | |
| 545 [self handleAction:ui::TextEditCommand::CUT | 553 [self handleAction:ui::TextEditCommand::CUT |
| 546 keyCode:ui::VKEY_X | 554 keyCode:ui::VKEY_X |
| 547 domCode:ui::DomCode::US_X | 555 domCode:ui::DomCode::US_X |
| 548 eventFlags:ui::EF_CONTROL_DOWN]; | 556 eventFlags:ui::EF_CONTROL_DOWN]; |
| 549 } | 557 } |
| 550 | 558 |
| 551 - (void)copy:(id)sender { | 559 - (void)copy:(id)sender { |
| 552 DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::COPY)); | |
| 553 [self handleAction:ui::TextEditCommand::COPY | 560 [self handleAction:ui::TextEditCommand::COPY |
| 554 keyCode:ui::VKEY_C | 561 keyCode:ui::VKEY_C |
| 555 domCode:ui::DomCode::US_C | 562 domCode:ui::DomCode::US_C |
| 556 eventFlags:ui::EF_CONTROL_DOWN]; | 563 eventFlags:ui::EF_CONTROL_DOWN]; |
| 557 } | 564 } |
| 558 | 565 |
| 559 - (void)paste:(id)sender { | 566 - (void)paste:(id)sender { |
| 560 DCHECK( | |
| 561 textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)); | |
| 562 [self handleAction:ui::TextEditCommand::PASTE | 567 [self handleAction:ui::TextEditCommand::PASTE |
| 563 keyCode:ui::VKEY_V | 568 keyCode:ui::VKEY_V |
| 564 domCode:ui::DomCode::US_V | 569 domCode:ui::DomCode::US_V |
| 565 eventFlags:ui::EF_CONTROL_DOWN]; | 570 eventFlags:ui::EF_CONTROL_DOWN]; |
| 566 } | 571 } |
| 567 | 572 |
| 568 - (void)selectAll:(id)sender { | 573 - (void)selectAll:(id)sender { |
| 569 DCHECK(textInputClient_->IsTextEditCommandEnabled( | |
| 570 ui::TextEditCommand::SELECT_ALL)); | |
| 571 [self handleAction:ui::TextEditCommand::SELECT_ALL | 574 [self handleAction:ui::TextEditCommand::SELECT_ALL |
| 572 keyCode:ui::VKEY_A | 575 keyCode:ui::VKEY_A |
| 573 domCode:ui::DomCode::US_A | 576 domCode:ui::DomCode::US_A |
| 574 eventFlags:ui::EF_CONTROL_DOWN]; | 577 eventFlags:ui::EF_CONTROL_DOWN]; |
| 575 } | 578 } |
| 576 | 579 |
| 577 // BaseView implementation. | 580 // BaseView implementation. |
| 578 | 581 |
| 579 // Don't use tracking areas from BaseView. BridgedContentView's tracks | 582 // Don't use tracking areas from BaseView. BridgedContentView's tracks |
| 580 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. | 583 // NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible. |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 textInputClient_->ConfirmCompositionText(); | 1374 textInputClient_->ConfirmCompositionText(); |
| 1372 } | 1375 } |
| 1373 | 1376 |
| 1374 - (NSArray*)validAttributesForMarkedText { | 1377 - (NSArray*)validAttributesForMarkedText { |
| 1375 return @[]; | 1378 return @[]; |
| 1376 } | 1379 } |
| 1377 | 1380 |
| 1378 // NSUserInterfaceValidations protocol implementation. | 1381 // NSUserInterfaceValidations protocol implementation. |
| 1379 | 1382 |
| 1380 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 1383 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 1381 if (!textInputClient_) | 1384 ui::TextEditCommand command = GetTextEditCommandForMenuAction([item action]); |
| 1385 | |
| 1386 if (command == ui::TextEditCommand::INVALID_COMMAND) | |
| 1382 return NO; | 1387 return NO; |
| 1383 | 1388 |
| 1384 SEL action = [item action]; | 1389 if (textInputClient_) |
| 1390 return textInputClient_->IsTextEditCommandEnabled(command); | |
| 1385 | 1391 |
| 1386 if (action == @selector(undo:)) | 1392 // We can't simply return NO since views like Labels which do not implement |
| 1387 return textInputClient_->IsTextEditCommandEnabled( | 1393 // the TextInputClient interface, may also need to intercept these menu |
| 1388 ui::TextEditCommand::UNDO); | 1394 // actions. As a rough approximation, check whether the focused view can |
| 1389 if (action == @selector(redo:)) | 1395 // process accelerators. This works since BrowserView also dispatches |
| 1390 return textInputClient_->IsTextEditCommandEnabled( | 1396 // Cut/Copy/Paste edit commands in the Chrome menu using accelerators. |
| 1391 ui::TextEditCommand::REDO); | 1397 views::FocusManager* focus_manager = |
| 1392 if (action == @selector(cut:)) | 1398 hostedView_->GetWidget()->GetFocusManager(); |
| 1393 return textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::CUT); | 1399 return focus_manager && focus_manager->GetFocusedView() && |
| 1394 if (action == @selector(copy:)) | 1400 focus_manager->GetFocusedView()->CanHandleAccelerators(); |
| 1395 return textInputClient_->IsTextEditCommandEnabled( | |
| 1396 ui::TextEditCommand::COPY); | |
| 1397 if (action == @selector(paste:)) | |
| 1398 return textInputClient_->IsTextEditCommandEnabled( | |
| 1399 ui::TextEditCommand::PASTE); | |
| 1400 if (action == @selector(selectAll:)) | |
| 1401 return textInputClient_->IsTextEditCommandEnabled( | |
| 1402 ui::TextEditCommand::SELECT_ALL); | |
| 1403 | |
| 1404 return NO; | |
| 1405 } | 1401 } |
| 1406 | 1402 |
| 1407 // NSDraggingSource protocol implementation. | 1403 // NSDraggingSource protocol implementation. |
| 1408 | 1404 |
| 1409 - (NSDragOperation)draggingSession:(NSDraggingSession*)session | 1405 - (NSDragOperation)draggingSession:(NSDraggingSession*)session |
| 1410 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { | 1406 sourceOperationMaskForDraggingContext:(NSDraggingContext)context { |
| 1411 return NSDragOperationEvery; | 1407 return NSDragOperationEvery; |
| 1412 } | 1408 } |
| 1413 | 1409 |
| 1414 - (void)draggingSession:(NSDraggingSession*)session | 1410 - (void)draggingSession:(NSDraggingSession*)session |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1433 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1429 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1434 } | 1430 } |
| 1435 | 1431 |
| 1436 - (id)accessibilityFocusedUIElement { | 1432 - (id)accessibilityFocusedUIElement { |
| 1437 if (!hostedView_) | 1433 if (!hostedView_) |
| 1438 return nil; | 1434 return nil; |
| 1439 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1435 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
| 1440 } | 1436 } |
| 1441 | 1437 |
| 1442 @end | 1438 @end |
| OLD | NEW |