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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_resource_cache.cc

Issue 10092017: Mac: Prevent NTP mousewheel events from being suppressed on Lion. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix scrolling when over page switcher. Created 8 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/webui/ntp/ntp_resource_cache.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "ui/gfx/sys_color_change_listener.h" 51 #include "ui/gfx/sys_color_change_listener.h"
52 52
53 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS) 53 #if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
54 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 54 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
55 #elif defined(OS_MACOSX) 55 #elif defined(OS_MACOSX)
56 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 56 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
57 #elif defined(TOOLKIT_GTK) 57 #elif defined(TOOLKIT_GTK)
58 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" 58 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h"
59 #endif 59 #endif
60 60
61 #if defined(OS_MACOSX)
62 #include "base/mac/mac_util.h"
63 #endif
64
61 using base::Time; 65 using base::Time;
62 using content::BrowserThread; 66 using content::BrowserThread;
63 67
64 namespace { 68 namespace {
65 69
66 // The URL for the the Learn More page shown on incognito new tab. 70 // The URL for the the Learn More page shown on incognito new tab.
67 const char kLearnMoreIncognitoUrl[] = 71 const char kLearnMoreIncognitoUrl[] =
68 #if defined(OS_CHROMEOS) 72 #if defined(OS_CHROMEOS)
69 "https://www.google.com/support/chromeos/bin/answer.py?answer=95464"; 73 "https://www.google.com/support/chromeos/bin/answer.py?answer=95464";
70 #else 74 #else
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 173
170 // Is the current time within a given date range? 174 // Is the current time within a given date range?
171 bool InDateRange(double begin, double end) { 175 bool InDateRange(double begin, double end) {
172 Time start_time = Time::FromDoubleT(begin); 176 Time start_time = Time::FromDoubleT(begin);
173 Time end_time = Time::FromDoubleT(end); 177 Time end_time = Time::FromDoubleT(end);
174 return start_time < Time::Now() && end_time > Time::Now(); 178 return start_time < Time::Now() && end_time > Time::Now();
175 } 179 }
176 180
177 } // namespace 181 } // namespace
178 182
179 NTPResourceCache::NTPResourceCache(Profile* profile) : profile_(profile) { 183 NTPResourceCache::NTPResourceCache(Profile* profile)
184 : profile_(profile), isSwipeTrackingFromScrollEventsEnabled_(false) {
180 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 185 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
181 content::Source<ThemeService>( 186 content::Source<ThemeService>(
182 ThemeServiceFactory::GetForProfile(profile))); 187 ThemeServiceFactory::GetForProfile(profile)));
183 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, 188 registrar_.Add(this, chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED,
184 content::NotificationService::AllSources()); 189 content::NotificationService::AllSources());
185 registrar_.Add(this, chrome::NTP4_INTRO_PREF_CHANGED, 190 registrar_.Add(this, chrome::NTP4_INTRO_PREF_CHANGED,
186 content::NotificationService::AllSources()); 191 content::NotificationService::AllSources());
187 192
188 // Watch for pref changes that cause us to need to invalidate the HTML cache. 193 // Watch for pref changes that cause us to need to invalidate the HTML cache.
189 pref_change_registrar_.Init(profile_->GetPrefs()); 194 pref_change_registrar_.Init(profile_->GetPrefs());
190 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this); 195 pref_change_registrar_.Add(prefs::kSyncAcknowledgedSyncTypes, this);
191 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); 196 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
192 pref_change_registrar_.Add(prefs::kNtpShownPage, this); 197 pref_change_registrar_.Add(prefs::kNtpShownPage, this);
193 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, this); 198 pref_change_registrar_.Add(prefs::kSyncPromoShowNTPBubble, this);
194 } 199 }
195 200
196 NTPResourceCache::~NTPResourceCache() {} 201 NTPResourceCache::~NTPResourceCache() {}
197 202
203 bool NTPResourceCache::InvalidateNewTabCache() {
Evan Stade 2012/04/17 21:29:53 s/InvalidateNewTabCache/NewTabCacheNeedsRefresh/g
Patrick Dubroy 2012/04/18 14:43:06 Done.
204 #if defined(OS_MACOSX)
205 // Invalidate if the current value is different from the cached value.
206 bool swipe_tracking_enabled =
207 base::mac::IsSwipeTrackingFromScrollEventsEnabled();
208 if (swipe_tracking_enabled != isSwipeTrackingFromScrollEventsEnabled_) {
209 isSwipeTrackingFromScrollEventsEnabled_ = swipe_tracking_enabled;
210 return true;
211 }
212 #endif
213 return false;
214 }
215
198 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) { 216 RefCountedMemory* NTPResourceCache::GetNewTabHTML(bool is_incognito) {
199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
200 if (is_incognito) { 218 if (is_incognito) {
201 if (!new_tab_incognito_html_.get()) 219 if (!new_tab_incognito_html_.get())
202 CreateNewTabIncognitoHTML(); 220 CreateNewTabIncognitoHTML();
203 } else { 221 } else {
204 if (!new_tab_html_.get()) 222 if (!new_tab_html_.get() || InvalidateNewTabCache())
205 CreateNewTabHTML(); 223 CreateNewTabHTML();
206 } 224 }
207 return is_incognito ? new_tab_incognito_html_.get() : 225 return is_incognito ? new_tab_incognito_html_.get() :
208 new_tab_html_.get(); 226 new_tab_html_.get();
209 } 227 }
210 228
211 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) { 229 RefCountedMemory* NTPResourceCache::GetNewTabCSS(bool is_incognito) {
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
213 if (is_incognito) { 231 if (is_incognito) {
214 if (!new_tab_incognito_css_.get()) 232 if (!new_tab_incognito_css_.get())
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 localized_strings.SetBoolean("appInstallHintEnabled", 376 localized_strings.SetBoolean("appInstallHintEnabled",
359 NewTabUI::ShouldShowAppInstallHint()); 377 NewTabUI::ShouldShowAppInstallHint());
360 localized_strings.SetString("appInstallHintText", 378 localized_strings.SetString("appInstallHintText",
361 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL)); 379 l10n_util::GetStringUTF16(IDS_NEW_TAB_APP_INSTALL_HINT_LABEL));
362 localized_strings.SetBoolean("isSuggestionsPageEnabled", 380 localized_strings.SetBoolean("isSuggestionsPageEnabled",
363 NewTabUI::IsSuggestionsPageEnabled()); 381 NewTabUI::IsSuggestionsPageEnabled());
364 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps()); 382 localized_strings.SetBoolean("showApps", NewTabUI::ShouldShowApps());
365 localized_strings.SetString("hideSessionMenuItemText", 383 localized_strings.SetString("hideSessionMenuItemText",
366 l10n_util::GetStringUTF16(IDS_POLICY_HIDE)); 384 l10n_util::GetStringUTF16(IDS_POLICY_HIDE));
367 385
386 // On Mac OS X 10.7+, horizontal scrolling can be treated as a back or
387 // forward gesture. Pass through a flag that indicates whether or not that
388 // feature is enabled.
389 #if defined(OS_MACOSX)
390 localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled",
391 base::mac::IsSwipeTrackingFromScrollEventsEnabled());
Evan Stade 2012/04/17 21:29:53 use the member var to avoid these ifdefs
Patrick Dubroy 2012/04/18 14:43:06 Done.
392 #else
393 localized_strings.SetBoolean("isSwipeTrackingFromScrollEventsEnabled",
394 false);
395 #endif
396
368 #if defined(OS_CHROMEOS) 397 #if defined(OS_CHROMEOS)
369 localized_strings.SetString("expandMenu", 398 localized_strings.SetString("expandMenu",
370 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND)); 399 l10n_util::GetStringUTF16(IDS_NEW_TAB_CLOSE_MENU_EXPAND));
371 #endif 400 #endif
372 401
373 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings); 402 NewTabPageHandler::GetLocalizedValues(profile_, &localized_strings);
374 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings); 403 NTPLoginHandler::GetLocalizedValues(profile_, &localized_strings);
375 404
376 // Don't initiate the sync related message passing with the page if the sync 405 // Don't initiate the sync related message passing with the page if the sync
377 // code is not present. 406 // code is not present.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 // Get our template. 581 // Get our template.
553 static const base::StringPiece new_tab_theme_css( 582 static const base::StringPiece new_tab_theme_css(
554 ResourceBundle::GetSharedInstance().GetRawDataResource( 583 ResourceBundle::GetSharedInstance().GetRawDataResource(
555 IDR_NEW_TAB_4_THEME_CSS)); 584 IDR_NEW_TAB_4_THEME_CSS));
556 585
557 // Create the string from our template and the replacements. 586 // Create the string from our template and the replacements.
558 std::string css_string; 587 std::string css_string;
559 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); 588 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL);
560 new_tab_css_ = base::RefCountedString::TakeString(&css_string); 589 new_tab_css_ = base::RefCountedString::TakeString(&css_string);
561 } 590 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698