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

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

Issue 2072653002: Experiments for using textfieldy context menus Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/controls/menu/menu_runner_impl_cocoa.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
(...skipping 17 matching lines...) Expand all
28 #import "ui/views/cocoa/bridged_native_widget.h" 28 #import "ui/views/cocoa/bridged_native_widget.h"
29 #import "ui/views/cocoa/drag_drop_client_mac.h" 29 #import "ui/views/cocoa/drag_drop_client_mac.h"
30 #include "ui/views/controls/menu/menu_config.h" 30 #include "ui/views/controls/menu/menu_config.h"
31 #include "ui/views/controls/menu/menu_controller.h" 31 #include "ui/views/controls/menu/menu_controller.h"
32 #include "ui/views/view.h" 32 #include "ui/views/view.h"
33 #include "ui/views/widget/native_widget_mac.h" 33 #include "ui/views/widget/native_widget_mac.h"
34 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
35 35
36 using views::MenuController; 36 using views::MenuController;
37 37
38 @interface TextShim : NSText {
39 BridgedContentView* owner_;
40 }
41 @end
42
43 @implementation TextShim
44
45 - (id)initWithOwner:(BridgedContentView*)owner {
46 if ((self = [super initWithFrame:NSZeroRect])) {
47 owner_ = owner;
48 }
49 return self;
50 }
51
52 @end
53
38 namespace { 54 namespace {
39 55
40 NSString* const kFullKeyboardAccessChangedNotification = 56 NSString* const kFullKeyboardAccessChangedNotification =
41 @"com.apple.KeyboardUIModeDidChange"; 57 @"com.apple.KeyboardUIModeDidChange";
42 58
43 // Returns true if all four corners of |rect| are contained inside |path|. 59 // Returns true if all four corners of |rect| are contained inside |path|.
44 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { 60 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) {
45 return [path containsPoint:rect.origin] && 61 return [path containsPoint:rect.origin] &&
46 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, 62 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width,
47 rect.origin.y)] && 63 rect.origin.y)] &&
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // Apple's documentation says that NSTrackingActiveAlways is incompatible 280 // Apple's documentation says that NSTrackingActiveAlways is incompatible
265 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. 281 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp.
266 cursorTrackingArea_.reset([[CrTrackingArea alloc] 282 cursorTrackingArea_.reset([[CrTrackingArea alloc]
267 initWithRect:NSZeroRect 283 initWithRect:NSZeroRect
268 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | 284 options:NSTrackingMouseMoved | NSTrackingCursorUpdate |
269 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect 285 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect
270 owner:self 286 owner:self
271 userInfo:nil]); 287 userInfo:nil]);
272 [self addTrackingArea:cursorTrackingArea_.get()]; 288 [self addTrackingArea:cursorTrackingArea_.get()];
273 289
290 textBridge_.reset([[TextShim alloc] initWithOwner:self]);
291
274 // Get notified whenever Full Keyboard Access mode is changed. 292 // Get notified whenever Full Keyboard Access mode is changed.
275 [[NSDistributedNotificationCenter defaultCenter] 293 [[NSDistributedNotificationCenter defaultCenter]
276 addObserver:self 294 addObserver:self
277 selector:@selector(onFullKeyboardAccessModeChanged:) 295 selector:@selector(onFullKeyboardAccessModeChanged:)
278 name:kFullKeyboardAccessChangedNotification 296 name:kFullKeyboardAccessChangedNotification
279 object:nil]; 297 object:nil];
280 298
281 // Initialize the focus manager with the correct keyboard accessibility 299 // Initialize the focus manager with the correct keyboard accessibility
282 // setting. 300 // setting.
283 [self updateFullKeyboardAccess]; 301 [self updateFullKeyboardAccess];
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 - (void)updateFullKeyboardAccess { 377 - (void)updateFullKeyboardAccess {
360 if (!hostedView_) 378 if (!hostedView_)
361 return; 379 return;
362 380
363 views::FocusManager* focusManager = 381 views::FocusManager* focusManager =
364 hostedView_->GetWidget()->GetFocusManager(); 382 hostedView_->GetWidget()->GetFocusManager();
365 if (focusManager) 383 if (focusManager)
366 focusManager->SetKeyboardAccessible([NSApp isFullKeyboardAccessEnabled]); 384 focusManager->SetKeyboardAccessible([NSApp isFullKeyboardAccessEnabled]);
367 } 385 }
368 386
387 - (NSView*)contextMenuView {
388 if (textInputClient_)
389 return textBridge_;
390 return self;
391 }
392
369 // BridgedContentView private implementation. 393 // BridgedContentView private implementation.
370 394
371 - (void)handleKeyEvent:(NSEvent*)theEvent { 395 - (void)handleKeyEvent:(NSEvent*)theEvent {
372 if (!hostedView_) 396 if (!hostedView_)
373 return; 397 return;
374 398
375 DCHECK(theEvent); 399 DCHECK(theEvent);
376 ui::KeyEvent event(theEvent); 400 ui::KeyEvent event(theEvent);
377 if (DispatchEventToMenu(hostedView_->GetWidget(), event.key_code())) 401 if (DispatchEventToMenu(hostedView_->GetWidget(), event.key_code()))
378 return; 402 return;
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 // Currently we only support reading and writing plain strings. 1031 // Currently we only support reading and writing plain strings.
1008 - (id)validRequestorForSendType:(NSString*)sendType 1032 - (id)validRequestorForSendType:(NSString*)sendType
1009 returnType:(NSString*)returnType { 1033 returnType:(NSString*)returnType {
1010 BOOL canWrite = [sendType isEqualToString:NSStringPboardType] && 1034 BOOL canWrite = [sendType isEqualToString:NSStringPboardType] &&
1011 [self selectedRange].length > 0; 1035 [self selectedRange].length > 0;
1012 BOOL canRead = [returnType isEqualToString:NSStringPboardType]; 1036 BOOL canRead = [returnType isEqualToString:NSStringPboardType];
1013 // Valid if (sendType, returnType) is either (string, nil), (nil, string), 1037 // Valid if (sendType, returnType) is either (string, nil), (nil, string),
1014 // or (string, string). 1038 // or (string, string).
1015 BOOL valid = textInputClient_ && ((canWrite && (canRead || !returnType)) || 1039 BOOL valid = textInputClient_ && ((canWrite && (canRead || !returnType)) ||
1016 (canRead && (canWrite || !sendType))); 1040 (canRead && (canWrite || !sendType)));
1041 //NOTREACHED();
1017 return valid ? self : [super validRequestorForSendType:sendType 1042 return valid ? self : [super validRequestorForSendType:sendType
1018 returnType:returnType]; 1043 returnType:returnType];
1019 } 1044 }
1020 1045
1021 // NSServicesRequests informal protocol. 1046 // NSServicesRequests informal protocol.
1022 1047
1023 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard types:(NSArray*)types { 1048 - (BOOL)writeSelectionToPasteboard:(NSPasteboard*)pboard types:(NSArray*)types {
1024 DCHECK([types containsObject:NSStringPboardType]); 1049 DCHECK([types containsObject:NSStringPboardType]);
1025 if (!textInputClient_) 1050 if (!textInputClient_)
1026 return NO; 1051 return NO;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 } 1258 }
1234 1259
1235 return [super accessibilityAttributeValue:attribute]; 1260 return [super accessibilityAttributeValue:attribute];
1236 } 1261 }
1237 1262
1238 - (id)accessibilityHitTest:(NSPoint)point { 1263 - (id)accessibilityHitTest:(NSPoint)point {
1239 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1264 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1240 } 1265 }
1241 1266
1242 @end 1267 @end
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/controls/menu/menu_runner_impl_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698