Chromium Code Reviews| Index: ui/views/cocoa/bridged_content_view.mm |
| diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm |
| index 041e9c572acb77fc5c1c8ea8d5293eb0f20383fa..6c55f114d775ae5943f2a48abce1e1ba88aec534 100644 |
| --- a/ui/views/cocoa/bridged_content_view.mm |
| +++ b/ui/views/cocoa/bridged_content_view.mm |
| @@ -247,6 +247,22 @@ bool IsTextRTL(const ui::TextInputClient* client) { |
| return str.autorelease(); |
| } |
| +ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { |
| + if (action == @selector(undo:)) |
| + return ui::TextEditCommand::UNDO; |
| + if (action == @selector(redo:)) |
| + return ui::TextEditCommand::REDO; |
| + if (action == @selector(cut:)) |
| + return ui::TextEditCommand::CUT; |
| + if (action == @selector(copy:)) |
| + return ui::TextEditCommand::COPY; |
| + if (action == @selector(paste:)) |
| + return ui::TextEditCommand::PASTE; |
| + if (action == @selector(selectAll:)) |
| + return ui::TextEditCommand::SELECT_ALL; |
| + return ui::TextEditCommand::INVALID_COMMAND; |
| +} |
| + |
| } // namespace |
| @interface BridgedContentView () |
| @@ -520,12 +536,6 @@ - (void)insertTextInternal:(id)text { |
| } |
| - (void)undo:(id)sender { |
| - // 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.
|
| - // done here because the actors sending these actions should be calling |
| - // validateUserInterfaceItem: before enabling UI that allows these messages to |
| - // be sent. Checking it here would be too late to provide correct UI feedback |
| - // (e.g. there will be no "beep"). |
| - DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::UNDO)); |
| [self handleAction:ui::TextEditCommand::UNDO |
| keyCode:ui::VKEY_Z |
| domCode:ui::DomCode::US_Z |
| @@ -533,7 +543,6 @@ - (void)undo:(id)sender { |
| } |
| - (void)redo:(id)sender { |
| - DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::REDO)); |
| [self handleAction:ui::TextEditCommand::REDO |
| keyCode:ui::VKEY_Z |
| domCode:ui::DomCode::US_Z |
| @@ -541,7 +550,6 @@ - (void)redo:(id)sender { |
| } |
| - (void)cut:(id)sender { |
| - DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::CUT)); |
| [self handleAction:ui::TextEditCommand::CUT |
| keyCode:ui::VKEY_X |
| domCode:ui::DomCode::US_X |
| @@ -549,7 +557,6 @@ - (void)cut:(id)sender { |
| } |
| - (void)copy:(id)sender { |
| - DCHECK(textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::COPY)); |
| [self handleAction:ui::TextEditCommand::COPY |
| keyCode:ui::VKEY_C |
| domCode:ui::DomCode::US_C |
| @@ -557,8 +564,6 @@ - (void)copy:(id)sender { |
| } |
| - (void)paste:(id)sender { |
| - DCHECK( |
| - textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::PASTE)); |
| [self handleAction:ui::TextEditCommand::PASTE |
| keyCode:ui::VKEY_V |
| domCode:ui::DomCode::US_V |
| @@ -566,8 +571,6 @@ - (void)paste:(id)sender { |
| } |
| - (void)selectAll:(id)sender { |
| - DCHECK(textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::SELECT_ALL)); |
| [self handleAction:ui::TextEditCommand::SELECT_ALL |
| keyCode:ui::VKEY_A |
| domCode:ui::DomCode::US_A |
| @@ -1378,30 +1381,23 @@ - (NSArray*)validAttributesForMarkedText { |
| // NSUserInterfaceValidations protocol implementation. |
| - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| - if (!textInputClient_) |
| - return NO; |
| + ui::TextEditCommand command = GetTextEditCommandForMenuAction([item action]); |
| - SEL action = [item action]; |
| - |
| - if (action == @selector(undo:)) |
| - return textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::UNDO); |
| - if (action == @selector(redo:)) |
| - return textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::REDO); |
| - if (action == @selector(cut:)) |
| - return textInputClient_->IsTextEditCommandEnabled(ui::TextEditCommand::CUT); |
| - if (action == @selector(copy:)) |
| - return textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::COPY); |
| - if (action == @selector(paste:)) |
| - return textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::PASTE); |
| - if (action == @selector(selectAll:)) |
| - return textInputClient_->IsTextEditCommandEnabled( |
| - ui::TextEditCommand::SELECT_ALL); |
| + if (command == ui::TextEditCommand::INVALID_COMMAND) |
| + return NO; |
| - return NO; |
| + if (textInputClient_) |
| + return textInputClient_->IsTextEditCommandEnabled(command); |
| + |
| + // We can't simply return NO since views like Labels which do not implement |
| + // the TextInputClient interface, may also need to intercept these menu |
| + // actions. As a rough approximation, check whether the focused view can |
| + // process accelerators. This works since BrowserView also dispatches |
| + // Cut/Copy/Paste edit commands in the Chrome menu using accelerators. |
| + views::FocusManager* focus_manager = |
| + hostedView_->GetWidget()->GetFocusManager(); |
| + return focus_manager && focus_manager->GetFocusedView() && |
| + focus_manager->GetFocusedView()->CanHandleAccelerators(); |
| } |
| // NSDraggingSource protocol implementation. |