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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 12631008: alternate ntp: implement Show/HideBars API to reduce jank when showing/hiding bars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert obsolete changes in search.h/cc Created 7 years, 9 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 | Annotate | Revision Log
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/browser/ui/search/search_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include "chrome/browser/instant/search.h" 7 #include "chrome/browser/instant/search.h"
8 #include "chrome/common/render_messages.h"
8 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
9 #include "content/public/browser/navigation_entry.h" 10 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
12 13
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper); 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(chrome::search::SearchTabHelper);
14 15
15 namespace { 16 namespace {
16 17
17 bool IsNTP(const content::WebContents* contents) { 18 bool IsNTP(const content::WebContents* contents) {
(...skipping 10 matching lines...) Expand all
28 bool IsSearchResults(const content::WebContents* contents) { 29 bool IsSearchResults(const content::WebContents* contents) {
29 return !chrome::search::GetSearchTerms(contents).empty(); 30 return !chrome::search::GetSearchTerms(contents).empty();
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 namespace chrome { 35 namespace chrome {
35 namespace search { 36 namespace search {
36 37
37 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) 38 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
38 : is_search_enabled_(chrome::search::IsInstantExtendedAPIEnabled()), 39 : WebContentsObserver(web_contents),
40 is_search_enabled_(chrome::search::IsInstantExtendedAPIEnabled()),
39 user_input_in_progress_(false), 41 user_input_in_progress_(false),
40 web_contents_(web_contents) { 42 web_contents_(web_contents) {
41 if (!is_search_enabled_) 43 if (!is_search_enabled_)
42 return; 44 return;
43 45
44 registrar_.Add( 46 registrar_.Add(
45 this, 47 this,
46 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 48 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
47 content::Source<content::NavigationController>( 49 content::Source<content::NavigationController>(
48 &web_contents->GetController())); 50 &web_contents->GetController()));
49 } 51 }
50 52
51 SearchTabHelper::~SearchTabHelper() { 53 SearchTabHelper::~SearchTabHelper() {
52 } 54 }
53 55
54 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, 56 void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress,
55 bool cancelling) { 57 bool cancelling) {
56 if (!is_search_enabled_) 58 if (!is_search_enabled_)
57 return; 59 return;
58 60
59 user_input_in_progress_ = user_input_in_progress; 61 user_input_in_progress_ = user_input_in_progress;
60 if (!user_input_in_progress && !cancelling) 62 if (!user_input_in_progress && !cancelling)
61 return; 63 return;
62 64
63 UpdateModel(); 65 UpdateModelMode();
dhollowa 2013/03/14 00:30:58 UpdateMode would be fine.
kuan 2013/03/14 00:44:18 Done.
64 } 66 }
65 67
66 void SearchTabHelper::NavigationEntryUpdated() { 68 void SearchTabHelper::NavigationEntryUpdated() {
67 if (!is_search_enabled_) 69 if (!is_search_enabled_)
68 return; 70 return;
69 71
70 UpdateModel(); 72 UpdateModelMode();
71 } 73 }
72 74
73 void SearchTabHelper::Observe( 75 void SearchTabHelper::Observe(
74 int type, 76 int type,
75 const content::NotificationSource& source, 77 const content::NotificationSource& source,
76 const content::NotificationDetails& details) { 78 const content::NotificationDetails& details) {
77 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); 79 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type);
78 UpdateModel(); 80 UpdateModelMode();
79 } 81 }
80 82
81 void SearchTabHelper::UpdateModel() { 83 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) {
84 bool handled = true;
85 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message)
86 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars,
87 OnSearchBoxShowBars)
88 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars,
89 OnSearchBoxHideBars)
90 IPC_MESSAGE_UNHANDLED(handled = false)
91 IPC_END_MESSAGE_MAP()
92 return handled;
93 }
94
95 void SearchTabHelper::UpdateModelMode() {
82 Mode::Type type = Mode::MODE_DEFAULT; 96 Mode::Type type = Mode::MODE_DEFAULT;
83 Mode::Origin origin = Mode::ORIGIN_DEFAULT; 97 Mode::Origin origin = Mode::ORIGIN_DEFAULT;
84 if (IsNTP(web_contents_)) { 98 if (IsNTP(web_contents_)) {
85 type = Mode::MODE_NTP; 99 type = Mode::MODE_NTP;
86 origin = Mode::ORIGIN_NTP; 100 origin = Mode::ORIGIN_NTP;
87 } else if (IsSearchResults(web_contents_)) { 101 } else if (IsSearchResults(web_contents_)) {
88 type = Mode::MODE_SEARCH_RESULTS; 102 type = Mode::MODE_SEARCH_RESULTS;
89 origin = Mode::ORIGIN_SEARCH; 103 origin = Mode::ORIGIN_SEARCH;
90 } 104 }
91 if (user_input_in_progress_) 105 if (user_input_in_progress_)
92 type = Mode::MODE_SEARCH_SUGGESTIONS; 106 type = Mode::MODE_SEARCH_SUGGESTIONS;
93 model_.SetMode(Mode(type, origin)); 107 model_.SetMode(Mode(type, origin));
94 } 108 }
95 109
110 void SearchTabHelper::OnSearchBoxShowBars(int page_id) {
111 if (web_contents()->IsActiveEntry(page_id))
112 model_.SetTopBarsVisible(true);
113 }
114
115 void SearchTabHelper::OnSearchBoxHideBars(int page_id) {
116 if (web_contents()->IsActiveEntry(page_id)) {
117 model_.SetTopBarsVisible(false);
118 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id()));
119 }
120 }
121
96 } // namespace search 122 } // namespace search
97 } // namespace chrome 123 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698