summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-12 01:40:28 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-12 01:40:28 +0000
commitfe4ccbef2c5d92d2fce6d4c2fd49b69248275f9b (patch)
tree909bc9ca9296cf4d935e222e2011160381eeb38e
parent30179058aa633f1052869d75936a09dd8e7b9cf7 (diff)
downloadchromium_src-fe4ccbef2c5d92d2fce6d4c2fd49b69248275f9b.zip
chromium_src-fe4ccbef2c5d92d2fce6d4c2fd49b69248275f9b.tar.gz
chromium_src-fe4ccbef2c5d92d2fce6d4c2fd49b69248275f9b.tar.bz2
[Macs] Adds a RenderWidgetHostView method to tell the view to take focus only on a mouse down event. This will allow us to click on instant results without dismissing the omnibox popup.
BUG=56385 TEST=No visible impact, yet. TEST=Should still be able to tab from the omnibox into webpages. TEST=Clicking on a webpage should transfer focus to the page. Review URL: http://codereview.chromium.org/3535015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62222 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/instant/instant_loader.cc10
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view.h6
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.h3
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm22
-rw-r--r--chrome/browser/renderer_host/test/test_render_view_host.h1
5 files changed, 41 insertions, 1 deletions
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc
index 0df775a..f1e7dd3 100644
--- a/chrome/browser/instant/instant_loader.cc
+++ b/chrome/browser/instant/instant_loader.cc
@@ -638,6 +638,10 @@ TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type) {
if (preview_contents_->GetRenderWidgetHostView()) {
preview_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()->
set_paint_observer(NULL);
+#if defined(OS_MACOSX)
+ preview_contents_->GetRenderWidgetHostView()->
+ SetTakesFocusOnlyOnMouseDown(false);
+#endif
}
preview_contents_->set_delegate(NULL);
preview_tab_contents_delegate_->Reset();
@@ -700,6 +704,12 @@ void InstantLoader::PreviewPainted() {
void InstantLoader::ShowPreview() {
if (!ready_) {
ready_ = true;
+#if defined(OS_MACOSX)
+ if (preview_contents_->GetRenderWidgetHostView()) {
+ preview_contents_->GetRenderWidgetHostView()->
+ SetTakesFocusOnlyOnMouseDown(true);
+ }
+#endif
delegate_->ShowInstantLoader(this);
}
}
diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h
index 4258a86..86c2abc 100644
--- a/chrome/browser/renderer_host/render_widget_host_view.h
+++ b/chrome/browser/renderer_host/render_widget_host_view.h
@@ -177,6 +177,12 @@ class RenderWidgetHostView {
virtual VideoLayer* AllocVideoLayer(const gfx::Size& size) = 0;
#if defined(OS_MACOSX)
+ // Tells the view whether or not to accept first responder status. If |flag|
+ // is true, the view does not accept first responder status and instead
+ // manually becomes first responder when it receives a mouse down event. If
+ // |flag| is false, the view participates in the key-view chain as normal.
+ virtual void SetTakesFocusOnlyOnMouseDown(bool flag) = 0;
+
// Display a native control popup menu for WebKit.
virtual void ShowPopupWithItems(gfx::Rect bounds,
int item_height,
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h
index aeac96f..16a78fc 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h
@@ -45,6 +45,7 @@ class RWHVMEditCommandHelper;
@private
scoped_ptr<RenderWidgetHostViewMac> renderWidgetHostView_;
BOOL canBeKeyView_;
+ BOOL takesFocusOnlyOnMouseDown_;
BOOL closeOnDeactivate_;
BOOL rendererAccessible_;
BOOL accessibilityRequested_;
@@ -128,6 +129,7 @@ class RWHVMEditCommandHelper;
@property(assign, nonatomic) NSRect caretRect;
- (void)setCanBeKeyView:(BOOL)can;
+- (void)setTakesFocusOnlyOnMouseDown:(BOOL)b;
- (void)setCloseOnDeactivate:(BOOL)b;
- (void)setToolTipAtMousePoint:(NSString *)string;
// Set frame, then notify the RenderWidgetHost that the frame has been changed,
@@ -204,6 +206,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
virtual void SelectionChanged(const std::string& text);
virtual BackingStore* AllocBackingStore(const gfx::Size& size);
virtual VideoLayer* AllocVideoLayer(const gfx::Size& size);
+ virtual void SetTakesFocusOnlyOnMouseDown(bool flag);
virtual void ShowPopupWithItems(gfx::Rect bounds,
int item_height,
double item_font_size,
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index bbcb160..414e283 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -805,6 +805,11 @@ VideoLayer* RenderWidgetHostViewMac::AllocVideoLayer(
return NULL;
}
+// Sets whether or not to accept first responder status.
+void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) {
+ [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag];
+}
+
// Display a popup menu for WebKit using Cocoa widgets.
void RenderWidgetHostViewMac::ShowPopupWithItems(
gfx::Rect bounds,
@@ -1179,6 +1184,7 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
renderWidgetHostView_.reset(r);
canBeKeyView_ = YES;
+ takesFocusOnlyOnMouseDown_ = NO;
closeOnDeactivate_ = NO;
rendererAccessible_ =
@@ -1194,11 +1200,25 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
canBeKeyView_ = can;
}
+- (void)setTakesFocusOnlyOnMouseDown:(BOOL)b {
+ takesFocusOnlyOnMouseDown_ = b;
+}
+
- (void)setCloseOnDeactivate:(BOOL)b {
closeOnDeactivate_ = b;
}
- (void)mouseEvent:(NSEvent*)theEvent {
+ // TODO(rohitrao): Probably need to handle other mouse down events here.
+ if ([theEvent type] == NSLeftMouseDown && takesFocusOnlyOnMouseDown_) {
+ if (renderWidgetHostView_->render_widget_host_)
+ renderWidgetHostView_->render_widget_host_->OnMouseActivate();
+
+ // Manually take focus after the click but before forwarding it to the
+ // renderer.
+ [[self window] makeFirstResponder:self];
+ }
+
// Don't cancel child popups; killing them on a mouse click would prevent the
// user from positioning the insertion point in the text field spawning the
// popup. A click outside the text field would cause the text field to drop
@@ -1680,7 +1700,7 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
if (!renderWidgetHostView_->render_widget_host_)
return NO;
- return canBeKeyView_;
+ return canBeKeyView_ && !takesFocusOnlyOnMouseDown_;
}
- (BOOL)becomeFirstResponder {
diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h
index 30b7e29..2312ba3 100644
--- a/chrome/browser/renderer_host/test/test_render_view_host.h
+++ b/chrome/browser/renderer_host/test/test_render_view_host.h
@@ -89,6 +89,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView {
virtual BackingStore* AllocBackingStore(const gfx::Size& size);
virtual VideoLayer* AllocVideoLayer(const gfx::Size& size);
#if defined(OS_MACOSX)
+ virtual void SetTakesFocusOnlyOnMouseDown(bool flag) {}
virtual void ShowPopupWithItems(gfx::Rect bounds,
int item_height,
double item_font_size,