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

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: Added unit tests 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_focused_(false),
67 is_key_capture_enabled_(false), 68 is_key_capture_enabled_(false),
68 display_instant_results_(false), 69 display_instant_results_(false),
69 omnibox_font_size_(0), 70 omnibox_font_size_(0),
70 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), 71 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize),
71 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { 72 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) {
72 } 73 }
73 74
74 SearchBox::~SearchBox() { 75 SearchBox::~SearchBox() {
75 } 76 }
76 77
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 OnDetermineIfPageSupportsInstant) 195 OnDetermineIfPageSupportsInstant)
195 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, 196 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
196 OnAutocompleteResults) 197 OnAutocompleteResults)
197 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, 198 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed,
198 OnUpOrDownKeyPressed) 199 OnUpOrDownKeyPressed)
199 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxEscKeyPressed, OnEscKeyPressed) 200 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxEscKeyPressed, OnEscKeyPressed)
200 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection, 201 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection,
201 OnCancelSelection) 202 OnCancelSelection)
202 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, 203 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults,
203 OnSetDisplayInstantResults) 204 OnSetDisplayInstantResults)
204 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, 205 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged,
samarth 2013/05/22 04:40:56 nit: fits on one line?
Donn Denman 2013/05/22 17:37:36 Done.
205 OnKeyCaptureChange) 206 OnFocusChanged)
206 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, 207 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged,
207 OnThemeChanged) 208 OnThemeChanged)
208 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, 209 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation,
209 OnFontInformationReceived) 210 OnFontInformationReceived)
210 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, 211 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged,
211 OnMostVisitedChanged) 212 OnMostVisitedChanged)
212 IPC_MESSAGE_UNHANDLED(handled = false) 213 IPC_MESSAGE_UNHANDLED(handled = false)
213 IPC_END_MESSAGE_MAP() 214 IPC_END_MESSAGE_MAP()
214 return handled; 215 return handled;
215 } 216 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 SetQuery(query, verbatim); 347 SetQuery(query, verbatim);
347 selection_start_ = selection_start; 348 selection_start_ = selection_start;
348 selection_end_ = selection_end; 349 selection_end_ = selection_end;
349 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 350 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
350 DVLOG(1) << render_view() << " OnKeyPress ESC"; 351 DVLOG(1) << render_view() << " OnKeyPress ESC";
351 extensions_v8::SearchBoxExtension::DispatchEscKeyPress( 352 extensions_v8::SearchBoxExtension::DispatchEscKeyPress(
352 render_view()->GetWebView()->mainFrame()); 353 render_view()->GetWebView()->mainFrame());
353 } 354 }
354 } 355 }
355 356
356 void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) { 357 void SearchBox::OnFocusChanged(OmniboxFocusState new_focus_state,
357 if (is_key_capture_enabled != is_key_capture_enabled_ && 358 OmniboxFocusChangeReason reason) {
358 render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 359 bool key_capture_enabled = new_focus_state == OMNIBOX_FOCUS_INVISIBLE;
359 is_key_capture_enabled_ = is_key_capture_enabled; 360 if (key_capture_enabled != is_key_capture_enabled_) {
360 DVLOG(1) << render_view() << " OnKeyCaptureChange"; 361 is_key_capture_enabled_ = key_capture_enabled;
samarth 2013/05/22 04:40:56 Put this inside the if below, or otherwise the sta
Donn Denman 2013/05/22 17:37:36 Done.
Donn Denman 2013/05/22 17:37:36 I was wondering about this (and should have put in
361 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( 362 // Tell the page if the key capture mode changed unless the focus state
363 // changed because of TYPING. This is because in that case, the browser
364 // hasn't really stopped capturing key strokes.
365 //
366 // (More practically, if we don't do this check, the page would receive
367 // onkeycapturechange before the corresponding onchange, and the page would
368 // have no way of telling whether the keycapturechange happened because of
369 // some actual user action or just because they started typing.)
370 if (reason != OMNIBOX_FOCUS_CHANGE_TYPING &&
371 render_view()->GetWebView() &&
372 render_view()->GetWebView()->mainFrame()) {
373 DVLOG(1) << render_view() << " OnKeyCaptureChange";
374 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
375 render_view()->GetWebView()->mainFrame());
376 }
377 }
378 bool is_focused = new_focus_state == OMNIBOX_FOCUS_VISIBLE;
379 if (is_focused != is_focused_) {
380 is_focused_ = is_focused;
381 DVLOG(1) << render_view() << " OnFocusChange";
382 extensions_v8::SearchBoxExtension::DispatchFocusChange(
362 render_view()->GetWebView()->mainFrame()); 383 render_view()->GetWebView()->mainFrame());
363 } 384 }
364 } 385 }
365 386
366 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { 387 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) {
367 display_instant_results_ = display_instant_results; 388 display_instant_results_ = display_instant_results;
368 } 389 }
369 390
370 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { 391 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
371 if (IsThemeInfoEqual(theme_info, theme_info_)) 392 if (IsThemeInfoEqual(theme_info, theme_info_))
(...skipping 22 matching lines...) Expand all
394 } 415 }
395 416
396 void SearchBox::Reset() { 417 void SearchBox::Reset() {
397 query_.clear(); 418 query_.clear();
398 verbatim_ = false; 419 verbatim_ = false;
399 query_is_restricted_ = false; 420 query_is_restricted_ = false;
400 selection_start_ = 0; 421 selection_start_ = 0;
401 selection_end_ = 0; 422 selection_end_ = 0;
402 popup_bounds_ = gfx::Rect(); 423 popup_bounds_ = gfx::Rect();
403 start_margin_ = 0; 424 start_margin_ = 0;
425 is_focused_ = false;
404 is_key_capture_enabled_ = false; 426 is_key_capture_enabled_ = false;
405 theme_info_ = ThemeBackgroundInfo(); 427 theme_info_ = ThemeBackgroundInfo();
406 // Don't reset display_instant_results_ to prevent clearing it on committed 428 // 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 429 // 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. 430 // 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 431 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never
410 // changes. 432 // changes.
411 } 433 }
412 434
413 void SearchBox::SetQuery(const string16& query, bool verbatim) { 435 void SearchBox::SetQuery(const string16& query, bool verbatim) {
(...skipping 21 matching lines...) Expand all
435 std::vector<InstantMostVisitedItemIDPair>* items) const { 457 std::vector<InstantMostVisitedItemIDPair>* items) const {
436 return most_visited_items_cache_.GetCurrentItems(items); 458 return most_visited_items_cache_.GetCurrentItems(items);
437 } 459 }
438 460
439 bool SearchBox::GetMostVisitedItemWithID( 461 bool SearchBox::GetMostVisitedItemWithID(
440 InstantRestrictedID most_visited_item_id, 462 InstantRestrictedID most_visited_item_id,
441 InstantMostVisitedItem* item) const { 463 InstantMostVisitedItem* item) const {
442 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, 464 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id,
443 item); 465 item);
444 } 466 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698