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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include "chrome/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/omnibox_focus_state.h" 10 #include "chrome/common/omnibox_focus_state.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } // namespace 57 } // namespace
58 58
59 SearchBox::SearchBox(content::RenderView* render_view) 59 SearchBox::SearchBox(content::RenderView* render_view)
60 : content::RenderViewObserver(render_view), 60 : content::RenderViewObserver(render_view),
61 content::RenderViewObserverTracker<SearchBox>(render_view), 61 content::RenderViewObserverTracker<SearchBox>(render_view),
62 verbatim_(false), 62 verbatim_(false),
63 query_is_restricted_(false), 63 query_is_restricted_(false),
64 selection_start_(0), 64 selection_start_(0),
65 selection_end_(0), 65 selection_end_(0),
66 start_margin_(0), 66 start_margin_(0),
67 is_key_capture_enabled_(false), 67 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
68 display_instant_results_(false), 68 display_instant_results_(false),
69 omnibox_font_size_(0), 69 omnibox_font_size_(0),
70 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), 70 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize),
71 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { 71 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) {
72 } 72 }
73 73
74 SearchBox::~SearchBox() { 74 SearchBox::~SearchBox() {
75 } 75 }
76 76
77 void SearchBox::SetSuggestions( 77 void SearchBox::SetSuggestions(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void SearchBox::HideBars() { 150 void SearchBox::HideBars() {
151 DVLOG(1) << render_view() << " HideBars"; 151 DVLOG(1) << render_view() << " HideBars";
152 render_view()->Send(new ChromeViewHostMsg_SearchBoxHideBars( 152 render_view()->Send(new ChromeViewHostMsg_SearchBoxHideBars(
153 render_view()->GetRoutingID(), render_view()->GetPageId())); 153 render_view()->GetRoutingID(), render_view()->GetPageId()));
154 } 154 }
155 155
156 int SearchBox::GetStartMargin() const { 156 int SearchBox::GetStartMargin() const {
157 return static_cast<int>(start_margin_ / GetZoom()); 157 return static_cast<int>(start_margin_ / GetZoom());
158 } 158 }
159 159
160 bool SearchBox::is_focused() const {
161 return omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE;
162 }
163
164 bool SearchBox::is_key_capture_enabled() const {
165 return omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE;
166 }
167
160 gfx::Rect SearchBox::GetPopupBounds() const { 168 gfx::Rect SearchBox::GetPopupBounds() const {
161 double zoom = GetZoom(); 169 double zoom = GetZoom();
162 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom), 170 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom),
163 static_cast<int>(popup_bounds_.y() / zoom), 171 static_cast<int>(popup_bounds_.y() / zoom),
164 static_cast<int>(popup_bounds_.width() / zoom), 172 static_cast<int>(popup_bounds_.width() / zoom),
165 static_cast<int>(popup_bounds_.height() / zoom)); 173 static_cast<int>(popup_bounds_.height() / zoom));
166 } 174 }
167 175
168 void SearchBox::GetAutocompleteResults( 176 void SearchBox::GetAutocompleteResults(
169 std::vector<InstantAutocompleteResultIDPair>* results) const { 177 std::vector<InstantAutocompleteResultIDPair>* results) const {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 SetQuery(query, verbatim); 354 SetQuery(query, verbatim);
347 selection_start_ = selection_start; 355 selection_start_ = selection_start;
348 selection_end_ = selection_end; 356 selection_end_ = selection_end;
349 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 357 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
350 DVLOG(1) << render_view() << " OnKeyPress ESC"; 358 DVLOG(1) << render_view() << " OnKeyPress ESC";
351 extensions_v8::SearchBoxExtension::DispatchEscKeyPress( 359 extensions_v8::SearchBoxExtension::DispatchEscKeyPress(
352 render_view()->GetWebView()->mainFrame()); 360 render_view()->GetWebView()->mainFrame());
353 } 361 }
354 } 362 }
355 363
356 void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) { 364 void SearchBox::OnKeyCaptureChange(OmniboxFocusState new_focus_state,
357 if (is_key_capture_enabled != is_key_capture_enabled_ && 365 OmniboxFocusChangeReason reason) {
358 render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 366 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.
359 is_key_capture_enabled_ = is_key_capture_enabled; 367 OmniboxFocusState previous_focus_state = omnibox_focus_state_;
360 DVLOG(1) << render_view() << " OnKeyCaptureChange"; 368 omnibox_focus_state_ = new_focus_state;
361 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( 369 if (render_view()->GetWebView() &&
362 render_view()->GetWebView()->mainFrame()); 370 render_view()->GetWebView()->mainFrame()) {
371 DVLOG(1) << render_view() << " OnKeyCaptureChange";
372 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
373 render_view()->GetWebView()->mainFrame());
374 if (omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE ||
375 previous_focus_state == OMNIBOX_FOCUS_VISIBLE) {
376 // Focus moved into, or out of, the real omnibox.
377 DVLOG(1) << render_view() << " OnFocusChange";
378 extensions_v8::SearchBoxExtension::DispatchFocusChange(
379 render_view()->GetWebView()->mainFrame());
380 }
381 }
363 } 382 }
364 } 383 }
365 384
366 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { 385 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) {
367 display_instant_results_ = display_instant_results; 386 display_instant_results_ = display_instant_results;
368 } 387 }
369 388
370 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { 389 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
371 if (IsThemeInfoEqual(theme_info, theme_info_)) 390 if (IsThemeInfoEqual(theme_info, theme_info_))
372 return; 391 return;
(...skipping 21 matching lines...) Expand all
394 } 413 }
395 414
396 void SearchBox::Reset() { 415 void SearchBox::Reset() {
397 query_.clear(); 416 query_.clear();
398 verbatim_ = false; 417 verbatim_ = false;
399 query_is_restricted_ = false; 418 query_is_restricted_ = false;
400 selection_start_ = 0; 419 selection_start_ = 0;
401 selection_end_ = 0; 420 selection_end_ = 0;
402 popup_bounds_ = gfx::Rect(); 421 popup_bounds_ = gfx::Rect();
403 start_margin_ = 0; 422 start_margin_ = 0;
404 is_key_capture_enabled_ = false; 423 omnibox_focus_state_ = OMNIBOX_FOCUS_NONE;
405 theme_info_ = ThemeBackgroundInfo(); 424 theme_info_ = ThemeBackgroundInfo();
406 // Don't reset display_instant_results_ to prevent clearing it on committed 425 // Don't reset display_instant_results_ to prevent clearing it on committed
407 // results pages in extended mode. Otherwise resetting it is a no-op because 426 // results pages in extended mode. Otherwise resetting it is a no-op because
408 // a new loader is created when it changes; see crbug.com/164662. 427 // a new loader is created when it changes; see crbug.com/164662.
409 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never 428 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never
410 // changes. 429 // changes.
411 } 430 }
412 431
413 void SearchBox::SetQuery(const string16& query, bool verbatim) { 432 void SearchBox::SetQuery(const string16& query, bool verbatim) {
414 query_ = query; 433 query_ = query;
(...skipping 20 matching lines...) Expand all
435 std::vector<InstantMostVisitedItemIDPair>* items) const { 454 std::vector<InstantMostVisitedItemIDPair>* items) const {
436 return most_visited_items_cache_.GetCurrentItems(items); 455 return most_visited_items_cache_.GetCurrentItems(items);
437 } 456 }
438 457
439 bool SearchBox::GetMostVisitedItemWithID( 458 bool SearchBox::GetMostVisitedItemWithID(
440 InstantRestrictedID most_visited_item_id, 459 InstantRestrictedID most_visited_item_id,
441 InstantMostVisitedItem* item) const { 460 InstantMostVisitedItem* item) const {
442 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, 461 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id,
443 item); 462 item);
444 } 463 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698