Commit 5d0cfcac authored by miu's avatar miu Committed by Commit bot

[Cocoa] Make TabContentsContainerView more testable for interactive_ui_tests.

Note: This change is a prerequisite for an upcoming change that will add
extensive interactive UI testing around Flash fullscreen, including the
Fullscreen-Within-Tab UI.

For all interactive_ui_tests, the UI widget being referenced by
VIEW_ID_TAB_CONTAINER was wrong whenever Flash fullscreen mode was
engaged.  This change tags the correct NSView with the identifier, and
gives it some simple focus-passing behavior, similar to
ui::views::WebView, to ensure that tests checking focus and/or
simulating a click on the tab container get the desired behavior.

Because the code changes to TabContentsContainerView are pretty much the
same, this change also addresses bug 421728, which makes clicking in the
"gray area" during Fullscreen-Within-Tab mode a request to give the tab
contents the focus.

BUG=403641,421728

Review URL: https://codereview.chromium.org/642143004

Cr-Commit-Position: refs/heads/master@{#300326}
parent fe606306
...@@ -37,7 +37,6 @@ class SpellCheckObserver; ...@@ -37,7 +37,6 @@ class SpellCheckObserver;
- (id)initWithRenderWidgetHost:(content::RenderWidgetHost*)renderWidgetHost; - (id)initWithRenderWidgetHost:(content::RenderWidgetHost*)renderWidgetHost;
- (void)viewGone:(NSView*)view;
- (BOOL)handleEvent:(NSEvent*)event; - (BOOL)handleEvent:(NSEvent*)event;
- (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item
isValidItem:(BOOL*)valid; isValidItem:(BOOL*)valid;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/view_id_util.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/spellcheck_messages.h" #include "chrome/common/spellcheck_messages.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -76,13 +75,6 @@ class SpellCheckObserver : public content::WebContentsObserver { ...@@ -76,13 +75,6 @@ class SpellCheckObserver : public content::WebContentsObserver {
self = [super init]; self = [super init];
if (self) { if (self) {
renderWidgetHost_ = renderWidgetHost; renderWidgetHost_ = renderWidgetHost;
// if |renderWidgetHost_| belongs to a BrowserPluginGuest, then it won't
// have a view yet.
if (renderWidgetHost_->GetView()) {
NSView* nativeView = renderWidgetHost_->GetView()->GetNativeView();
view_id_util::SetID(nativeView, VIEW_ID_TAB_CONTAINER);
}
if (renderWidgetHost_->IsRenderView()) { if (renderWidgetHost_->IsRenderView()) {
spellingObserver_.reset( spellingObserver_.reset(
new ChromeRenderWidgetHostViewMacDelegateInternal::SpellCheckObserver( new ChromeRenderWidgetHostViewMacDelegateInternal::SpellCheckObserver(
...@@ -99,10 +91,6 @@ class SpellCheckObserver : public content::WebContentsObserver { ...@@ -99,10 +91,6 @@ class SpellCheckObserver : public content::WebContentsObserver {
[super dealloc]; [super dealloc];
} }
- (void)viewGone:(NSView*)view {
view_id_util::UnsetID(view);
}
// Handle an event. All incoming key and mouse events flow through this // Handle an event. All incoming key and mouse events flow through this
// delegate method if implemented. Return YES if the event is fully handled, or // delegate method if implemented. Return YES if the event is fully handled, or
// NO if normal processing should take place. // NO if normal processing should take place.
......
...@@ -97,9 +97,22 @@ class BrowserFocusTest : public InProcessBrowserTest { ...@@ -97,9 +97,22 @@ class BrowserFocusTest : public InProcessBrowserTest {
for (size_t i = 0; i < 2; ++i) { for (size_t i = 0; i < 2; ++i) {
SCOPED_TRACE(base::StringPrintf("focus outer loop: %" PRIuS, i)); SCOPED_TRACE(base::StringPrintf("focus outer loop: %" PRIuS, i));
ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
// Mac requires an extra Tab key press to traverse the app menu button // Mac requires an extra Tab key press to traverse the app menu button
// iff "Full Keyboard Access" is enabled. This test code should probably // iff "Full Keyboard Access" is enabled. In reverse, four Tab key presses
// check the setting via NSApplication's isFullKeyboardAccessEnabled. // are required to traverse the back/forward buttons and the tab strip.
#if defined(OS_MACOSX)
if (ui_controls::IsFullKeyboardAccessEnabled()) {
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), key, false, reverse, false, false));
if (reverse) {
for (int j = 0; j < 3; ++j) {
ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), key, false, reverse, false, false));
}
}
}
#endif
for (size_t j = 0; j < arraysize(kExpectedIDs); ++j) { for (size_t j = 0; j < arraysize(kExpectedIDs); ++j) {
SCOPED_TRACE(base::StringPrintf("focus inner loop %" PRIuS, j)); SCOPED_TRACE(base::StringPrintf("focus inner loop %" PRIuS, j));
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#import "chrome/browser/themes/theme_properties.h" #import "chrome/browser/themes/theme_properties.h"
#import "chrome/browser/themes/theme_service.h" #import "chrome/browser/themes/theme_service.h"
#import "chrome/browser/ui/cocoa/themed_window.h" #import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/browser/ui/view_ids.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -165,6 +166,28 @@ class FullscreenObserver : public WebContentsObserver { ...@@ -165,6 +166,28 @@ class FullscreenObserver : public WebContentsObserver {
[[self layer] setBackgroundColor:cgBackgroundColor]; [[self layer] setBackgroundColor:cgBackgroundColor];
} }
- (ViewID)viewID {
return VIEW_ID_TAB_CONTAINER;
}
- (BOOL)acceptsFirstResponder {
return [[self subviews] count] > 0 &&
[[[self subviews] objectAtIndex:0] acceptsFirstResponder];
}
// When receiving a click-to-focus in the solid color area surrounding the
// WebContents' native view, immediately transfer focus to WebContents' native
// view.
- (BOOL)becomeFirstResponder {
if (![self acceptsFirstResponder])
return NO;
return [[self window] makeFirstResponder:[[self subviews] objectAtIndex:0]];
}
- (BOOL)canBecomeKeyView {
return NO; // Tab/Shift-Tab should focus the subview, not this view.
}
@end // @implementation TabContentsContainerView @end // @implementation TabContentsContainerView
@implementation TabContentsController @implementation TabContentsController
......
...@@ -54,6 +54,13 @@ bool IsViewFocused(const Browser* browser, ViewID vid) { ...@@ -54,6 +54,13 @@ bool IsViewFocused(const Browser* browser, ViewID vid) {
if (firstResponder == static_cast<NSResponder*>(view)) if (firstResponder == static_cast<NSResponder*>(view))
return true; return true;
// Handle special case for VIEW_ID_TAB_CONTAINER. The tab container NSView
// always transfers first responder status to its subview, so test whether
// |firstResponder| is a descendant.
if (vid == VIEW_ID_TAB_CONTAINER &&
[firstResponder isKindOfClass:[NSView class]])
return [static_cast<NSView*>(firstResponder) isDescendantOf:view];
// Handle the special case of focusing a TextField. // Handle the special case of focusing a TextField.
if ([firstResponder isKindOfClass:[NSTextView class]]) { if ([firstResponder isKindOfClass:[NSTextView class]]) {
NSView* delegate = static_cast<NSView*>([(NSTextView*)firstResponder NSView* delegate = static_cast<NSView*>([(NSTextView*)firstResponder
......
...@@ -1658,6 +1658,10 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged( ...@@ -1658,6 +1658,10 @@ void RenderWidgetHostViewMac::OnDisplayMetricsChanged(
renderWidgetHostView_.reset(r); renderWidgetHostView_.reset(r);
canBeKeyView_ = YES; canBeKeyView_ = YES;
// TODO(miu): |takesFocusOnlyOnMouseDown_| is not used anymore and should be
// removed along with the exposed RWHV interface methods.
// http://crbug.com/424766
takesFocusOnlyOnMouseDown_ = NO;
focusedPluginIdentifier_ = -1; focusedPluginIdentifier_ = -1;
// OpenGL support: // OpenGL support:
......
...@@ -97,6 +97,13 @@ class UIControlsAura; ...@@ -97,6 +97,13 @@ class UIControlsAura;
void InstallUIControlsAura(UIControlsAura* instance); void InstallUIControlsAura(UIControlsAura* instance);
#endif #endif
#if defined(OS_MACOSX)
// Returns true when tests need to use extra Tab and Shift-Tab key events
// to traverse to the desired item; because the application is configured to
// traverse more elements for accessibility reasons.
bool IsFullKeyboardAccessEnabled();
#endif
} // namespace ui_controls } // namespace ui_controls
#endif // UI_BASE_TEST_UI_CONTROLS_H_ #endif // UI_BASE_TEST_UI_CONTROLS_H_
...@@ -389,4 +389,8 @@ void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) { ...@@ -389,4 +389,8 @@ void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
FROM_HERE, base::Bind(&EventQueueWatcher, closure)); FROM_HERE, base::Bind(&EventQueueWatcher, closure));
} }
bool IsFullKeyboardAccessEnabled() {
return [NSApp isFullKeyboardAccessEnabled];
}
} // namespace ui_controls } // namespace ui_controls
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment