| 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 e3b3d8e0700380423e6c6130153aaaf0dde4fbb3..a151529dea03a7809be9ec3b0725f9f92c891d21 100644
|
| --- a/ui/views/cocoa/bridged_content_view.mm
|
| +++ b/ui/views/cocoa/bridged_content_view.mm
|
| @@ -8,12 +8,18 @@
|
| #import "base/mac/scoped_nsobject.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "ui/base/ime/text_input_client.h"
|
| +#import "ui/events/cocoa/cocoa_event_utils.h"
|
| +#include "ui/events/keycodes/dom3/dom_code.h"
|
| +#import "ui/events/keycodes/keyboard_code_conversion_mac.h"
|
| #include "ui/gfx/canvas_paint_mac.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| #include "ui/strings/grit/ui_strings.h"
|
| +#include "ui/views/controls/menu/menu_controller.h"
|
| #include "ui/views/view.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| +using views::MenuController;
|
| +
|
| namespace {
|
|
|
| // Convert a |point| in |source_window|'s AppKit coordinate system (origin at
|
| @@ -42,6 +48,15 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| // the event to NativeWidgetMac for handling.
|
| - (void)handleMouseEvent:(NSEvent*)theEvent;
|
|
|
| +// Handles an NSResponder Action Message by mapping it to the keyCode that
|
| +// toolkit-views expects internally. E.g. moveToBeginningOfLine: would pass
|
| +// ui::VKEY_HOME even though the Home key on Mac defaults to
|
| +// moveToBeginningOfDocument:. This approach also allows action messages a user
|
| +// may have remapped in ~/Library/KeyBindings/DefaultKeyBinding.dict to be
|
| +// catered for.
|
| +- (void)handleActionAsKey:(ui::KeyboardCode)keyCode
|
| + domCode:(ui::DomCode)domCode;
|
| +
|
| // Execute a command on the currently focused TextInputClient.
|
| // |commandId| should be a resource ID from ui_strings.grd.
|
| - (void)doCommandByID:(int)commandId;
|
| @@ -111,6 +126,23 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| hostedView_->GetWidget()->OnMouseEvent(&event);
|
| }
|
|
|
| +- (void)handleActionAsKey:(ui::KeyboardCode)keyCode
|
| + domCode:(ui::DomCode)domCode {
|
| + if (!hostedView_)
|
| + return;
|
| +
|
| + ui::KeyEvent event(ui::ET_KEY_PRESSED, keyCode, domCode,
|
| + ui::EventFlagsFromModifiers([NSEvent modifierFlags]));
|
| +
|
| + MenuController* menuController = MenuController::GetActiveInstance();
|
| + if (menuController &&
|
| + menuController->owner() == hostedView_->GetWidget() &&
|
| + menuController->OnWillDispatchEvent(event) == ui::POST_DISPATCH_NONE)
|
| + return;
|
| +
|
| + hostedView_->GetWidget()->OnKeyEvent(&event);
|
| +}
|
| +
|
| - (void)doCommandByID:(int)commandId {
|
| if (textInputClient_ && textInputClient_->IsEditingCommandEnabled(commandId))
|
| textInputClient_->ExecuteEditingCommand(commandId);
|
| @@ -147,10 +179,7 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| // NSResponder implementation.
|
|
|
| - (void)keyDown:(NSEvent*)theEvent {
|
| - if (textInputClient_)
|
| - [self interpretKeyEvents:@[ theEvent ]];
|
| - else
|
| - [super keyDown:theEvent];
|
| + [self interpretKeyEvents:@[ theEvent ]];
|
| }
|
|
|
| - (void)mouseDown:(NSEvent*)theEvent {
|
| @@ -221,8 +250,19 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| }
|
|
|
| - (void)insertText:(id)text {
|
| - if (textInputClient_)
|
| - textInputClient_->InsertText(base::SysNSStringToUTF16(text));
|
| + [self insertText:text replacementRange:NSMakeRange(NSNotFound, 0)];
|
| +}
|
| +
|
| +- (void)moveUp:(id)sender {
|
| + [self handleActionAsKey:ui::VKEY_UP domCode:ui::DomCode::ARROW_UP];
|
| +}
|
| +
|
| +- (void)moveDown:(id)sender {
|
| + [self handleActionAsKey:ui::VKEY_DOWN domCode:ui::DomCode::ARROW_DOWN];
|
| +}
|
| +
|
| +- (void)cancelOperation:(id)sender {
|
| + [self handleActionAsKey:ui::VKEY_ESCAPE domCode:ui::DomCode::ESCAPE];
|
| }
|
|
|
| // Support for Services in context menus.
|
| @@ -288,10 +328,12 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| }
|
|
|
| - (void)doCommandBySelector:(SEL)selector {
|
| - if ([self respondsToSelector:selector])
|
| + if ([self respondsToSelector:selector]) {
|
| [self performSelector:selector withObject:nil];
|
| - else
|
| + } else {
|
| + NSLog(@"Unmatched selector: %@\n", NSStringFromSelector(selector));
|
| [[self nextResponder] doCommandBySelector:selector];
|
| + }
|
| }
|
|
|
| - (NSRect)firstRectForCharacterRange:(NSRange)range
|
| @@ -305,11 +347,26 @@ gfx::Point MovePointToWindow(const NSPoint& point,
|
| }
|
|
|
| - (void)insertText:(id)text replacementRange:(NSRange)replacementRange {
|
| - if (!textInputClient_)
|
| + if (!hostedView_)
|
| return;
|
|
|
| if ([text isKindOfClass:[NSAttributedString class]])
|
| text = [text string];
|
| +
|
| + MenuController* menuController = MenuController::GetActiveInstance();
|
| + if (menuController && menuController->owner() == hostedView_->GetWidget()) {
|
| + DCHECK([text length] > 0);
|
| + ui::KeyEvent event(ui::ET_KEY_PRESSED,
|
| + ui::KeyboardCodeFromCharCode([text characterAtIndex:0]),
|
| + ui::DomCode::NONE,
|
| + ui::EventFlagsFromModifiers([NSEvent modifierFlags]));
|
| + if (menuController->OnWillDispatchEvent(event) == ui::POST_DISPATCH_NONE)
|
| + return;
|
| + }
|
| +
|
| + if (!textInputClient_)
|
| + return;
|
| +
|
| textInputClient_->DeleteRange(gfx::Range(replacementRange));
|
| textInputClient_->InsertText(base::SysNSStringToUTF16(text));
|
| }
|
|
|