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

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

Issue 923903002: MacViews: Merge single-character edits, map (and validate) undo and redo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase for r316774 (remove "ing" from "Editing") Created 5 years, 10 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/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "ui/base/ime/text_input_client.h" 10 #include "ui/base/ime/text_input_client.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Note: default key bindings in Mac can be read from StandardKeyBinding.dict 60 // Note: default key bindings in Mac can be read from StandardKeyBinding.dict
61 // which lives in /System/Library/Frameworks/AppKit.framework/Resources. Do 61 // which lives in /System/Library/Frameworks/AppKit.framework/Resources. Do
62 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to 62 // `plutil -convert xml1 -o StandardKeyBinding.xml StandardKeyBinding.dict` to
63 // get something readable. 63 // get something readable.
64 - (void)handleAction:(int)commandId 64 - (void)handleAction:(int)commandId
65 keyCode:(ui::KeyboardCode)keyCode 65 keyCode:(ui::KeyboardCode)keyCode
66 domCode:(ui::DomCode)domCode 66 domCode:(ui::DomCode)domCode
67 eventFlags:(int)eventFlags; 67 eventFlags:(int)eventFlags;
68 68
69 // Menu action handlers. 69 // Menu action handlers.
70 - (void)undo:(id)sender;
71 - (void)redo:(id)sender;
70 - (void)cut:(id)sender; 72 - (void)cut:(id)sender;
71 - (void)copy:(id)sender; 73 - (void)copy:(id)sender;
72 - (void)paste:(id)sender; 74 - (void)paste:(id)sender;
73 - (void)selectAll:(id)sender; 75 - (void)selectAll:(id)sender;
74 76
75 @end 77 @end
76 78
77 @implementation BridgedContentView 79 @implementation BridgedContentView
78 80
79 @synthesize hostedView = hostedView_; 81 @synthesize hostedView = hostedView_;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // performed. 160 // performed.
159 if (commandId && textInputClient_ && 161 if (commandId && textInputClient_ &&
160 textInputClient_->IsEditCommandEnabled(commandId)) 162 textInputClient_->IsEditCommandEnabled(commandId))
161 textInputClient_->SetEditCommandForNextKeyEvent(commandId); 163 textInputClient_->SetEditCommandForNextKeyEvent(commandId);
162 164
163 // Generate a synthetic event with the keycode toolkit-views expects. 165 // Generate a synthetic event with the keycode toolkit-views expects.
164 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags); 166 ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode, eventFlags);
165 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(event); 167 hostedView_->GetWidget()->GetInputMethod()->DispatchKeyEvent(event);
166 } 168 }
167 169
170 - (void)undo:(id)sender {
171 // This DCHECK is more strict than a similar check in handleAction:. It can be
172 // done here because the actors sending these actions should be calling
173 // validateUserInterfaceItem: before enabling UI that allows these messages to
174 // be sent. Checking it here would be too late to provide correct UI feedback
175 // (e.g. there will be no "beep").
176 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO));
177 [self handleAction:IDS_APP_UNDO
178 keyCode:ui::VKEY_Z
179 domCode:ui::DomCode::KEY_Z
180 eventFlags:ui::EF_CONTROL_DOWN];
181 }
182
183 - (void)redo:(id)sender {
184 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_REDO));
185 [self handleAction:IDS_APP_REDO
186 keyCode:ui::VKEY_Z
187 domCode:ui::DomCode::KEY_Z
188 eventFlags:ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN];
189 }
190
168 - (void)cut:(id)sender { 191 - (void)cut:(id)sender {
169 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_CUT)); 192 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_CUT));
170 [self handleAction:IDS_APP_CUT 193 [self handleAction:IDS_APP_CUT
171 keyCode:ui::VKEY_X 194 keyCode:ui::VKEY_X
172 domCode:ui::DomCode::KEY_X 195 domCode:ui::DomCode::KEY_X
173 eventFlags:ui::EF_CONTROL_DOWN]; 196 eventFlags:ui::EF_CONTROL_DOWN];
174 } 197 }
175 198
176 - (void)copy:(id)sender { 199 - (void)copy:(id)sender {
177 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_COPY)); 200 DCHECK(textInputClient_->IsEditCommandEnabled(IDS_APP_COPY));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (menuController && menuController->owner() == hostedView_->GetWidget()) 259 if (menuController && menuController->owner() == hostedView_->GetWidget())
237 return nil; 260 return nil;
238 261
239 return [super inputContext]; 262 return [super inputContext];
240 } 263 }
241 264
242 // NSResponder implementation. 265 // NSResponder implementation.
243 266
244 - (void)keyDown:(NSEvent*)theEvent { 267 - (void)keyDown:(NSEvent*)theEvent {
245 // Convert the event into an action message, according to OSX key mappings. 268 // Convert the event into an action message, according to OSX key mappings.
269 inKeyDown_ = YES;
246 [self interpretKeyEvents:@[ theEvent ]]; 270 [self interpretKeyEvents:@[ theEvent ]];
271 inKeyDown_ = NO;
247 } 272 }
248 273
249 - (void)mouseDown:(NSEvent*)theEvent { 274 - (void)mouseDown:(NSEvent*)theEvent {
250 [self handleMouseEvent:theEvent]; 275 [self handleMouseEvent:theEvent];
251 } 276 }
252 277
253 - (void)rightMouseDown:(NSEvent*)theEvent { 278 - (void)rightMouseDown:(NSEvent*)theEvent {
254 [self handleMouseEvent:theEvent]; 279 [self handleMouseEvent:theEvent];
255 } 280 }
256 281
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 swallowedAny = true; 586 swallowedAny = true;
562 // Ensure the menu remains active. 587 // Ensure the menu remains active.
563 menuController = MenuController::GetActiveInstance(); 588 menuController = MenuController::GetActiveInstance();
564 } 589 }
565 } 590 }
566 591
567 if (!textInputClient_) 592 if (!textInputClient_)
568 return; 593 return;
569 594
570 textInputClient_->DeleteRange(gfx::Range(replacementRange)); 595 textInputClient_->DeleteRange(gfx::Range(replacementRange));
571 textInputClient_->InsertText(base::SysNSStringToUTF16(text)); 596
597 // If a single character is inserted by keyDown's call to interpretKeyEvents:
598 // then use InsertChar() to allow editing events to be merged. Never send the
599 // key modifier flags to InsertChar since interpretKeyEvents: will filter out
600 // things that are actually commands, and 'Alt' on Mac actually inserts
601 // alternate characters (e.g. Alt+S is ß), so shouldn't be ignored.
msw 2015/02/18 19:10:42 nit: This comment is worded a little confusingly..
tapted 2015/02/19 03:19:10 Done. (now says If a single character is inserte
602 if (inKeyDown_ && [text length] == 1)
603 textInputClient_->InsertChar([text characterAtIndex:0], 0);
604 else
605 textInputClient_->InsertText(base::SysNSStringToUTF16(text));
572 } 606 }
573 607
574 - (NSRange)markedRange { 608 - (NSRange)markedRange {
575 if (!textInputClient_) 609 if (!textInputClient_)
576 return NSMakeRange(NSNotFound, 0); 610 return NSMakeRange(NSNotFound, 0);
577 611
578 gfx::Range range; 612 gfx::Range range;
579 textInputClient_->GetCompositionTextRange(&range); 613 textInputClient_->GetCompositionTextRange(&range);
580 return range.ToNSRange(); 614 return range.ToNSRange();
581 } 615 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 647 }
614 648
615 // NSUserInterfaceValidations protocol implementation. 649 // NSUserInterfaceValidations protocol implementation.
616 650
617 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { 651 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
618 if (!textInputClient_) 652 if (!textInputClient_)
619 return NO; 653 return NO;
620 654
621 SEL action = [item action]; 655 SEL action = [item action];
622 656
657 if (action == @selector(undo:))
658 return textInputClient_->IsEditCommandEnabled(IDS_APP_UNDO);
659 if (action == @selector(redo:))
660 return textInputClient_->IsEditCommandEnabled(IDS_APP_REDO);
623 if (action == @selector(cut:)) 661 if (action == @selector(cut:))
624 return textInputClient_->IsEditCommandEnabled(IDS_APP_CUT); 662 return textInputClient_->IsEditCommandEnabled(IDS_APP_CUT);
625 if (action == @selector(copy:)) 663 if (action == @selector(copy:))
626 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY); 664 return textInputClient_->IsEditCommandEnabled(IDS_APP_COPY);
627 if (action == @selector(paste:)) 665 if (action == @selector(paste:))
628 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE); 666 return textInputClient_->IsEditCommandEnabled(IDS_APP_PASTE);
629 if (action == @selector(selectAll:)) 667 if (action == @selector(selectAll:))
630 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL); 668 return textInputClient_->IsEditCommandEnabled(IDS_APP_SELECT_ALL);
631 669
632 return NO; 670 return NO;
633 } 671 }
634 672
635 // NSAccessibility informal protocol implementation. 673 // NSAccessibility informal protocol implementation.
636 674
637 - (id)accessibilityAttributeValue:(NSString*)attribute { 675 - (id)accessibilityAttributeValue:(NSString*)attribute {
638 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { 676 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
639 return @[ hostedView_->GetNativeViewAccessible() ]; 677 return @[ hostedView_->GetNativeViewAccessible() ];
640 } 678 }
641 679
642 return [super accessibilityAttributeValue:attribute]; 680 return [super accessibilityAttributeValue:attribute];
643 } 681 }
644 682
645 - (id)accessibilityHitTest:(NSPoint)point { 683 - (id)accessibilityHitTest:(NSPoint)point {
646 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 684 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
647 } 685 }
648 686
649 @end 687 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698