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

Unified Diff: chrome/renderer/searchbox/searchbox.cc

Issue 14646034: Add onfocuschange to the Extended Search API, with associated isFocused attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using KeyCaptureChange IPC for notification of focus change, and checking if it really changed in t… Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index d72a60cb974e1980cc468d7c80dacee9f005c40e..88e983584de4a89c7ee23e269ee510d8090db8d5 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -64,7 +64,7 @@ SearchBox::SearchBox(content::RenderView* render_view)
selection_start_(0),
selection_end_(0),
start_margin_(0),
- is_key_capture_enabled_(false),
+ omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
display_instant_results_(false),
omnibox_font_size_(0),
autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize),
@@ -157,6 +157,14 @@ int SearchBox::GetStartMargin() const {
return static_cast<int>(start_margin_ / GetZoom());
}
+bool SearchBox::is_focused() const {
+ return omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE;
+}
+
+bool SearchBox::is_key_capture_enabled() const {
+ return omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE;
+}
+
gfx::Rect SearchBox::GetPopupBounds() const {
double zoom = GetZoom();
return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom),
@@ -353,13 +361,24 @@ void SearchBox::OnCancelSelection(const string16& query,
}
}
-void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) {
- if (is_key_capture_enabled != is_key_capture_enabled_ &&
- render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- is_key_capture_enabled_ = is_key_capture_enabled;
- DVLOG(1) << render_view() << " OnKeyCaptureChange";
- extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
- render_view()->GetWebView()->mainFrame());
+void SearchBox::OnKeyCaptureChange(OmniboxFocusState new_focus_state,
+ OmniboxFocusChangeReason reason) {
+ if (new_focus_state != omnibox_focus_state_) {
samarth 2013/05/13 20:56:53 Sorry, this is all a little confusing so let me gi
Donn Denman 2013/05/13 23:44:50 Thanks for explaining this. Done.
+ OmniboxFocusState previous_focus_state = omnibox_focus_state_;
+ omnibox_focus_state_ = new_focus_state;
+ if (render_view()->GetWebView() &&
+ render_view()->GetWebView()->mainFrame()) {
+ DVLOG(1) << render_view() << " OnKeyCaptureChange";
+ extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
+ render_view()->GetWebView()->mainFrame());
+ if (omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE ||
+ previous_focus_state == OMNIBOX_FOCUS_VISIBLE) {
+ // Focus moved into, or out of, the real omnibox.
+ DVLOG(1) << render_view() << " OnFocusChange";
+ extensions_v8::SearchBoxExtension::DispatchFocusChange(
+ render_view()->GetWebView()->mainFrame());
+ }
+ }
}
}
@@ -401,7 +420,7 @@ void SearchBox::Reset() {
selection_end_ = 0;
popup_bounds_ = gfx::Rect();
start_margin_ = 0;
- is_key_capture_enabled_ = false;
+ omnibox_focus_state_ = OMNIBOX_FOCUS_NONE;
theme_info_ = ThemeBackgroundInfo();
// Don't reset display_instant_results_ to prevent clearing it on committed
// results pages in extended mode. Otherwise resetting it is a no-op because

Powered by Google App Engine
This is Rietveld 408576698