web_contents_view_mac.mm revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#import <Carbon/Carbon.h>
6
7#import "content/browser/web_contents/web_contents_view_mac.h"
8
9#include <string>
10
11#import "base/mac/scoped_sending_event.h"
12#include "base/message_loop/message_loop.h"
13#import "base/message_loop/message_pump_mac.h"
14#include "content/browser/renderer_host/popup_menu_helper_mac.h"
15#include "content/browser/renderer_host/render_view_host_factory.h"
16#include "content/browser/renderer_host/render_view_host_impl.h"
17#include "content/browser/renderer_host/render_widget_host_view_mac.h"
18#include "content/browser/web_contents/web_contents_impl.h"
19#import "content/browser/web_contents/web_drag_dest_mac.h"
20#import "content/browser/web_contents/web_drag_source_mac.h"
21#include "content/common/view_messages.h"
22#include "content/public/browser/web_contents_delegate.h"
23#include "content/public/browser/web_contents_view_delegate.h"
24#include "skia/ext/skia_utils_mac.h"
25#import "third_party/mozilla/NSPasteboard+Utils.h"
26#include "ui/base/clipboard/custom_data_helper.h"
27#import "ui/base/cocoa/focus_tracker.h"
28#include "ui/base/dragdrop/cocoa_dnd_util.h"
29#include "ui/gfx/image/image_skia_util_mac.h"
30
31using blink::WebDragOperation;
32using blink::WebDragOperationsMask;
33using content::DropData;
34using content::PopupMenuHelper;
35using content::RenderViewHostFactory;
36using content::RenderWidgetHostView;
37using content::RenderWidgetHostViewMac;
38using content::WebContents;
39using content::WebContentsImpl;
40using content::WebContentsViewMac;
41
42// Ensure that the blink::WebDragOperation enum values stay in sync with
43// NSDragOperation constants, since the code below static_casts between 'em.
44#define COMPILE_ASSERT_MATCHING_ENUM(name) \
45  COMPILE_ASSERT(int(NS##name) == int(blink::Web##name), enum_mismatch_##name)
46COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone);
47COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy);
48COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink);
49COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric);
50COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate);
51COMPILE_ASSERT_MATCHING_ENUM(DragOperationMove);
52COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete);
53COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery);
54
55@interface WebContentsViewCocoa (Private)
56- (id)initWithWebContentsViewMac:(WebContentsViewMac*)w;
57- (void)registerDragTypes;
58- (void)setCurrentDragOperation:(NSDragOperation)operation;
59- (DropData*)dropData;
60- (void)startDragWithDropData:(const DropData&)dropData
61            dragOperationMask:(NSDragOperation)operationMask
62                        image:(NSImage*)image
63                       offset:(NSPoint)offset;
64- (void)cancelDeferredClose;
65- (void)clearWebContentsView;
66- (void)closeTabAfterEvent;
67- (void)viewDidBecomeFirstResponder:(NSNotification*)notification;
68@end
69
70namespace content {
71WebContentsViewPort* CreateWebContentsView(
72    WebContentsImpl* web_contents,
73    WebContentsViewDelegate* delegate,
74    RenderViewHostDelegateView** render_view_host_delegate_view) {
75  WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate);
76  *render_view_host_delegate_view = rv;
77  return rv;
78}
79
80WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents,
81                                       WebContentsViewDelegate* delegate)
82    : web_contents_(web_contents),
83      delegate_(delegate),
84      allow_overlapping_views_(false),
85      overlay_view_(NULL),
86      underlay_view_(NULL) {
87}
88
89WebContentsViewMac::~WebContentsViewMac() {
90  // This handles the case where a renderer close call was deferred
91  // while the user was operating a UI control which resulted in a
92  // close.  In that case, the Cocoa view outlives the
93  // WebContentsViewMac instance due to Cocoa retain count.
94  [cocoa_view_ cancelDeferredClose];
95  [cocoa_view_ clearWebContentsView];
96}
97
98gfx::NativeView WebContentsViewMac::GetNativeView() const {
99  return cocoa_view_.get();
100}
101
102gfx::NativeView WebContentsViewMac::GetContentNativeView() const {
103  RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView();
104  if (!rwhv)
105    return NULL;
106  return rwhv->GetNativeView();
107}
108
109gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeWindow() const {
110  return [cocoa_view_.get() window];
111}
112
113void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const {
114  // Convert bounds to window coordinate space.
115  NSRect bounds =
116      [cocoa_view_.get() convertRect:[cocoa_view_.get() bounds] toView:nil];
117
118  // Convert bounds to screen coordinate space.
119  NSWindow* window = [cocoa_view_.get() window];
120  bounds.origin = [window convertBaseToScreen:bounds.origin];
121
122  // Flip y to account for screen flip.
123  NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
124  bounds.origin.y = [screen frame].size.height - bounds.origin.y
125      - bounds.size.height;
126  *out = gfx::Rect(NSRectToCGRect(bounds));
127}
128
129void WebContentsViewMac::StartDragging(
130    const DropData& drop_data,
131    WebDragOperationsMask allowed_operations,
132    const gfx::ImageSkia& image,
133    const gfx::Vector2d& image_offset,
134    const DragEventSourceInfo& event_info) {
135  // By allowing nested tasks, the code below also allows Close(),
136  // which would deallocate |this|.  The same problem can occur while
137  // processing -sendEvent:, so Close() is deferred in that case.
138  // Drags from web content do not come via -sendEvent:, this sets the
139  // same flag -sendEvent: would.
140  base::mac::ScopedSendingEvent sending_event_scoper;
141
142  // The drag invokes a nested event loop, arrange to continue
143  // processing events.
144  base::MessageLoop::ScopedNestableTaskAllower allow(
145      base::MessageLoop::current());
146  NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations);
147  NSPoint offset = NSPointFromCGPoint(
148      gfx::PointAtOffsetFromOrigin(image_offset).ToCGPoint());
149  [cocoa_view_ startDragWithDropData:drop_data
150                   dragOperationMask:mask
151                               image:gfx::NSImageFromImageSkia(image)
152                              offset:offset];
153}
154
155void WebContentsViewMac::OnTabCrashed(base::TerminationStatus /* status */,
156                                      int /* error_code */) {
157}
158
159void WebContentsViewMac::SizeContents(const gfx::Size& size) {
160  // TODO(brettw | japhet) This is a hack and should be removed.
161  // See web_contents_view.h.
162  gfx::Rect rect(gfx::Point(), size);
163  WebContentsViewCocoa* view = cocoa_view_.get();
164
165  NSPoint origin = [view frame].origin;
166  NSRect frame = [view flipRectToNSRect:rect];
167  frame.origin = NSMakePoint(NSMinX(frame) + origin.x,
168                             NSMinY(frame) + origin.y);
169  [view setFrame:frame];
170}
171
172void WebContentsViewMac::Focus() {
173  NSWindow* window = [cocoa_view_.get() window];
174  [window makeFirstResponder:GetContentNativeView()];
175  if (![window isVisible])
176    return;
177  [window makeKeyAndOrderFront:nil];
178}
179
180void WebContentsViewMac::SetInitialFocus() {
181  if (web_contents_->FocusLocationBarByDefault())
182    web_contents_->SetFocusToLocationBar(false);
183  else
184    [[cocoa_view_.get() window] makeFirstResponder:GetContentNativeView()];
185}
186
187void WebContentsViewMac::StoreFocus() {
188  // We're explicitly being asked to store focus, so don't worry if there's
189  // already a view saved.
190  focus_tracker_.reset(
191      [[FocusTracker alloc] initWithWindow:[cocoa_view_ window]]);
192}
193
194void WebContentsViewMac::RestoreFocus() {
195  // TODO(avi): Could we be restoring a view that's no longer in the key view
196  // chain?
197  if (!(focus_tracker_.get() &&
198        [focus_tracker_ restoreFocusInWindow:[cocoa_view_ window]])) {
199    // Fall back to the default focus behavior if we could not restore focus.
200    // TODO(shess): If location-bar gets focus by default, this will
201    // select-all in the field.  If there was a specific selection in
202    // the field when we navigated away from it, we should restore
203    // that selection.
204    SetInitialFocus();
205  }
206
207  focus_tracker_.reset(nil);
208}
209
210DropData* WebContentsViewMac::GetDropData() const {
211  return [cocoa_view_ dropData];
212}
213
214void WebContentsViewMac::UpdateDragCursor(WebDragOperation operation) {
215  [cocoa_view_ setCurrentDragOperation: operation];
216}
217
218void WebContentsViewMac::GotFocus() {
219  // This is only used in the views FocusManager stuff but it bleeds through
220  // all subclasses. http://crbug.com/21875
221}
222
223// This is called when the renderer asks us to take focus back (i.e., it has
224// iterated past the last focusable element on the page).
225void WebContentsViewMac::TakeFocus(bool reverse) {
226  if (reverse) {
227    [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()];
228  } else {
229    [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()];
230  }
231}
232
233void WebContentsViewMac::ShowContextMenu(const ContextMenuParams& params) {
234  // Allow delegates to handle the context menu operation first.
235  if (web_contents_->GetDelegate() &&
236      web_contents_->GetDelegate()->HandleContextMenu(params)) {
237    return;
238  }
239
240  if (delegate())
241    delegate()->ShowContextMenu(params);
242  else
243    DLOG(ERROR) << "Cannot show context menus without a delegate.";
244}
245
246// Display a popup menu for WebKit using Cocoa widgets.
247void WebContentsViewMac::ShowPopupMenu(
248    const gfx::Rect& bounds,
249    int item_height,
250    double item_font_size,
251    int selected_item,
252    const std::vector<MenuItem>& items,
253    bool right_aligned,
254    bool allow_multiple_selection) {
255  PopupMenuHelper popup_menu_helper(web_contents_->GetRenderViewHost());
256  popup_menu_helper.ShowPopupMenu(bounds, item_height, item_font_size,
257                                  selected_item, items, right_aligned,
258                                  allow_multiple_selection);
259}
260
261gfx::Rect WebContentsViewMac::GetViewBounds() const {
262  // This method is not currently used on mac.
263  NOTIMPLEMENTED();
264  return gfx::Rect();
265}
266
267void WebContentsViewMac::SetAllowOverlappingViews(bool overlapping) {
268  if (allow_overlapping_views_ == overlapping)
269    return;
270
271  allow_overlapping_views_ = overlapping;
272  RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>(
273      web_contents_->GetRenderWidgetHostView());
274  if (view)
275    view->SetAllowOverlappingViews(allow_overlapping_views_);
276}
277
278bool WebContentsViewMac::GetAllowOverlappingViews() const {
279  return allow_overlapping_views_;
280}
281
282void WebContentsViewMac::SetOverlayView(
283    WebContentsView* overlay, const gfx::Point& offset) {
284  DCHECK(!underlay_view_);
285  if (overlay_view_)
286    RemoveOverlayView();
287
288  overlay_view_ = static_cast<WebContentsViewMac*>(overlay);
289  DCHECK(!overlay_view_->overlay_view_);
290  overlay_view_->underlay_view_ = this;
291  overlay_view_offset_ = offset;
292  UpdateRenderWidgetHostViewOverlay();
293}
294
295void WebContentsViewMac::RemoveOverlayView() {
296  DCHECK(overlay_view_);
297
298  RenderWidgetHostViewMac* rwhv = static_cast<RenderWidgetHostViewMac*>(
299      web_contents_->GetRenderWidgetHostView());
300  if (rwhv)
301    rwhv->RemoveOverlayView();
302
303  overlay_view_->underlay_view_ = NULL;
304  overlay_view_ = NULL;
305}
306
307void WebContentsViewMac::UpdateRenderWidgetHostViewOverlay() {
308  RenderWidgetHostViewMac* rwhv = static_cast<RenderWidgetHostViewMac*>(
309      web_contents_->GetRenderWidgetHostView());
310  if (!rwhv)
311    return;
312
313  if (overlay_view_) {
314    RenderWidgetHostViewMac* overlay_rwhv =
315        static_cast<RenderWidgetHostViewMac*>(
316            overlay_view_->web_contents_->GetRenderWidgetHostView());
317    if (overlay_rwhv)
318      rwhv->SetOverlayView(overlay_rwhv, overlay_view_offset_);
319  }
320
321  if (underlay_view_) {
322    RenderWidgetHostViewMac* underlay_rwhv =
323        static_cast<RenderWidgetHostViewMac*>(
324            underlay_view_->web_contents_->GetRenderWidgetHostView());
325    if (underlay_rwhv)
326      underlay_rwhv->SetOverlayView(rwhv, underlay_view_->overlay_view_offset_);
327  }
328}
329
330void WebContentsViewMac::CreateView(
331    const gfx::Size& initial_size, gfx::NativeView context) {
332  WebContentsViewCocoa* view =
333      [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this];
334  cocoa_view_.reset(view);
335}
336
337RenderWidgetHostView* WebContentsViewMac::CreateViewForWidget(
338    RenderWidgetHost* render_widget_host) {
339  if (render_widget_host->GetView()) {
340    // During testing, the view will already be set up in most cases to the
341    // test view, so we don't want to clobber it with a real one. To verify that
342    // this actually is happening (and somebody isn't accidentally creating the
343    // view twice), we check for the RVH Factory, which will be set when we're
344    // making special ones (which go along with the special views).
345    DCHECK(RenderViewHostFactory::has_factory());
346    return render_widget_host->GetView();
347  }
348
349  RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>(
350      RenderWidgetHostView::CreateViewForWidget(render_widget_host));
351  if (delegate()) {
352    NSObject<RenderWidgetHostViewMacDelegate>* rw_delegate =
353        delegate()->CreateRenderWidgetHostViewDelegate(render_widget_host);
354    view->SetDelegate(rw_delegate);
355  }
356  view->SetAllowOverlappingViews(allow_overlapping_views_);
357
358  // Fancy layout comes later; for now just make it our size and resize it
359  // with us. In case there are other siblings of the content area, we want
360  // to make sure the content area is on the bottom so other things draw over
361  // it.
362  NSView* view_view = view->GetNativeView();
363  [view_view setFrame:[cocoa_view_.get() bounds]];
364  [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
365  // Add the new view below all other views; this also keeps it below any
366  // overlay view installed.
367  [cocoa_view_.get() addSubview:view_view
368                     positioned:NSWindowBelow
369                     relativeTo:nil];
370  // For some reason known only to Cocoa, the autorecalculation of the key view
371  // loop set on the window doesn't set the next key view when the subview is
372  // added. On 10.6 things magically work fine; on 10.5 they fail
373  // <http://crbug.com/61493>. Digging into Cocoa key view loop code yielded
374  // madness; TODO(avi,rohit): look at this again and figure out what's really
375  // going on.
376  [cocoa_view_.get() setNextKeyView:view_view];
377  return view;
378}
379
380RenderWidgetHostView* WebContentsViewMac::CreateViewForPopupWidget(
381    RenderWidgetHost* render_widget_host) {
382  return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host);
383}
384
385void WebContentsViewMac::SetPageTitle(const base::string16& title) {
386  // Meaningless on the Mac; widgets don't have a "title" attribute
387}
388
389
390void WebContentsViewMac::RenderViewCreated(RenderViewHost* host) {
391  // We want updates whenever the intrinsic width of the webpage changes.
392  // Put the RenderView into that mode. The preferred width is used for example
393  // when the "zoom" button in the browser window is clicked.
394  host->EnablePreferredSizeMode();
395}
396
397void WebContentsViewMac::RenderViewSwappedIn(RenderViewHost* host) {
398  UpdateRenderWidgetHostViewOverlay();
399}
400
401void WebContentsViewMac::SetOverscrollControllerEnabled(bool enabled) {
402}
403
404bool WebContentsViewMac::IsEventTracking() const {
405  return base::MessagePumpMac::IsHandlingSendEvent();
406}
407
408// Arrange to call CloseTab() after we're back to the main event loop.
409// The obvious way to do this would be PostNonNestableTask(), but that
410// will fire when the event-tracking loop polls for events.  So we
411// need to bounce the message via Cocoa, instead.
412void WebContentsViewMac::CloseTabAfterEventTracking() {
413  [cocoa_view_ cancelDeferredClose];
414  [cocoa_view_ performSelector:@selector(closeTabAfterEvent)
415                    withObject:nil
416                    afterDelay:0.0];
417}
418
419void WebContentsViewMac::CloseTab() {
420  web_contents_->Close(web_contents_->GetRenderViewHost());
421}
422
423}  // namespace content
424
425@implementation WebContentsViewCocoa
426
427- (id)initWithWebContentsViewMac:(WebContentsViewMac*)w {
428  self = [super initWithFrame:NSZeroRect];
429  if (self != nil) {
430    webContentsView_ = w;
431    dragDest_.reset(
432        [[WebDragDest alloc] initWithWebContentsImpl:[self webContents]]);
433    [self registerDragTypes];
434
435    [[NSNotificationCenter defaultCenter]
436         addObserver:self
437            selector:@selector(viewDidBecomeFirstResponder:)
438                name:kViewDidBecomeFirstResponder
439              object:nil];
440
441    if (webContentsView_->delegate()) {
442      [dragDest_ setDragDelegate:webContentsView_->delegate()->
443          GetDragDestDelegate()];
444    }
445  }
446  return self;
447}
448
449- (void)dealloc {
450  // Cancel any deferred tab closes, just in case.
451  [self cancelDeferredClose];
452
453  // This probably isn't strictly necessary, but can't hurt.
454  [self unregisterDraggedTypes];
455
456  [[NSNotificationCenter defaultCenter] removeObserver:self];
457
458  [super dealloc];
459}
460
461// Registers for the view for the appropriate drag types.
462- (void)registerDragTypes {
463  NSArray* types = [NSArray arrayWithObjects:
464      ui::kChromeDragDummyPboardType,
465      kWebURLsWithTitlesPboardType,
466      NSURLPboardType,
467      NSStringPboardType,
468      NSHTMLPboardType,
469      NSRTFPboardType,
470      NSFilenamesPboardType,
471      ui::kWebCustomDataPboardType,
472      nil];
473  [self registerForDraggedTypes:types];
474}
475
476- (void)setCurrentDragOperation:(NSDragOperation)operation {
477  [dragDest_ setCurrentOperation:operation];
478}
479
480- (DropData*)dropData {
481  return [dragDest_ currentDropData];
482}
483
484- (WebContentsImpl*)webContents {
485  if (webContentsView_ == NULL)
486    return NULL;
487  return webContentsView_->web_contents();
488}
489
490- (void)mouseEvent:(NSEvent*)theEvent {
491  WebContentsImpl* webContents = [self webContents];
492  if (webContents && webContents->GetDelegate()) {
493    NSPoint location = [NSEvent mouseLocation];
494    if ([theEvent type] == NSMouseMoved)
495      webContents->GetDelegate()->ContentsMouseEvent(
496          webContents, gfx::Point(location.x, location.y), true);
497    if ([theEvent type] == NSMouseExited)
498      webContents->GetDelegate()->ContentsMouseEvent(
499          webContents, gfx::Point(location.x, location.y), false);
500  }
501}
502
503- (void)setMouseDownCanMoveWindow:(BOOL)canMove {
504  mouseDownCanMoveWindow_ = canMove;
505}
506
507- (BOOL)mouseDownCanMoveWindow {
508  // This is needed to prevent mouseDowns from moving the window
509  // around.  The default implementation returns YES only for opaque
510  // views.  WebContentsViewCocoa does not draw itself in any way, but
511  // its subviews do paint their entire frames.  Returning NO here
512  // saves us the effort of overriding this method in every possible
513  // subview.
514  return mouseDownCanMoveWindow_;
515}
516
517- (void)pasteboard:(NSPasteboard*)sender provideDataForType:(NSString*)type {
518  [dragSource_ lazyWriteToPasteboard:sender
519                             forType:type];
520}
521
522- (void)startDragWithDropData:(const DropData&)dropData
523            dragOperationMask:(NSDragOperation)operationMask
524                        image:(NSImage*)image
525                       offset:(NSPoint)offset {
526  dragSource_.reset([[WebDragSource alloc]
527      initWithContents:[self webContents]
528                  view:self
529              dropData:&dropData
530                 image:image
531                offset:offset
532            pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard]
533     dragOperationMask:operationMask]);
534  [dragSource_ startDrag];
535}
536
537// NSDraggingSource methods
538
539// Returns what kind of drag operations are available. This is a required
540// method for NSDraggingSource.
541- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
542  if (dragSource_)
543    return [dragSource_ draggingSourceOperationMaskForLocal:isLocal];
544  // No web drag source - this is the case for dragging a file from the
545  // downloads manager. Default to copy operation. Note: It is desirable to
546  // allow the user to either move or copy, but this requires additional
547  // plumbing to update the download item's path once its moved.
548  return NSDragOperationCopy;
549}
550
551// Called when a drag initiated in our view ends.
552- (void)draggedImage:(NSImage*)anImage
553             endedAt:(NSPoint)screenPoint
554           operation:(NSDragOperation)operation {
555  [dragSource_ endDragAt:screenPoint operation:operation];
556
557  // Might as well throw out this object now.
558  dragSource_.reset();
559}
560
561// Called when a drag initiated in our view moves.
562- (void)draggedImage:(NSImage*)draggedImage movedTo:(NSPoint)screenPoint {
563  [dragSource_ moveDragTo:screenPoint];
564}
565
566// Called when a file drag is dropped and the promised files need to be written.
567- (NSArray*)namesOfPromisedFilesDroppedAtDestination:(NSURL*)dropDest {
568  if (![dropDest isFileURL])
569    return nil;
570
571  NSString* fileName = [dragSource_ dragPromisedFileTo:[dropDest path]];
572  if (!fileName)
573    return nil;
574
575  return @[ fileName ];
576}
577
578// NSDraggingDestination methods
579
580- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
581  return [dragDest_ draggingEntered:sender view:self];
582}
583
584- (void)draggingExited:(id<NSDraggingInfo>)sender {
585  [dragDest_ draggingExited:sender];
586}
587
588- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
589  return [dragDest_ draggingUpdated:sender view:self];
590}
591
592- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
593  return [dragDest_ performDragOperation:sender view:self];
594}
595
596- (void)cancelDeferredClose {
597  SEL aSel = @selector(closeTabAfterEvent);
598  [NSObject cancelPreviousPerformRequestsWithTarget:self
599                                           selector:aSel
600                                             object:nil];
601}
602
603- (void)clearWebContentsView {
604  webContentsView_ = NULL;
605  [dragSource_ clearWebContentsView];
606}
607
608- (void)closeTabAfterEvent {
609  webContentsView_->CloseTab();
610}
611
612- (void)viewDidBecomeFirstResponder:(NSNotification*)notification {
613  NSView* view = [notification object];
614  if (![[self subviews] containsObject:view])
615    return;
616
617  NSSelectionDirection direction =
618      [[[notification userInfo] objectForKey:kSelectionDirection]
619        unsignedIntegerValue];
620  if (direction == NSDirectSelection)
621    return;
622
623  [self webContents]->
624      FocusThroughTabTraversal(direction == NSSelectingPrevious);
625}
626
627@end
628