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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1438513003: [MD] Implement incognito colors as a NativeTheme (for Aura). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win, linux, android compiles issues Created 5 years, 1 month 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/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 template_url_service_(NULL), 149 template_url_service_(NULL),
150 dropdown_animation_offset_(0), 150 dropdown_animation_offset_(0),
151 web_contents_null_at_last_refresh_(true) { 151 web_contents_null_at_last_refresh_(true) {
152 edit_bookmarks_enabled_.Init( 152 edit_bookmarks_enabled_.Init(
153 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 153 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
154 base::Bind(&LocationBarView::UpdateWithoutTabRestore, 154 base::Bind(&LocationBarView::UpdateWithoutTabRestore,
155 base::Unretained(this))); 155 base::Unretained(this)));
156 156
157 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) 157 ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
158 ->AddZoomEventManagerObserver(this); 158 ->AddZoomEventManagerObserver(this);
159
160 if (ui::MaterialDesignController::IsModeMaterial()) {
161 set_background(new BackgroundWith1PxBorder(
162 GetColor(SecurityStateModel::NONE, BACKGROUND),
163 SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), is_popup_mode_));
164 }
165 } 159 }
166 160
167 LocationBarView::~LocationBarView() { 161 LocationBarView::~LocationBarView() {
168 if (template_url_service_) 162 if (template_url_service_)
169 template_url_service_->RemoveObserver(this); 163 template_url_service_->RemoveObserver(this);
170 164
171 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) 165 ui_zoom::ZoomEventManager::GetForBrowserContext(profile())
172 ->RemoveZoomEventManagerObserver(this); 166 ->RemoveZoomEventManagerObserver(this);
173 } 167 }
174 168
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const int kBubbleInteriorVerticalPadding = 209 const int kBubbleInteriorVerticalPadding =
216 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1; 210 ui::MaterialDesignController::IsModeMaterial() ? 2 : 1;
217 const int bubble_padding = 211 const int bubble_padding =
218 GetVerticalEdgeThickness() + 212 GetVerticalEdgeThickness() +
219 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) + 213 GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) +
220 kBubbleInteriorVerticalPadding; 214 kBubbleInteriorVerticalPadding;
221 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2); 215 const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2);
222 gfx::FontList bubble_font_list = 216 gfx::FontList bubble_font_list =
223 font_list.DeriveWithHeightUpperBound(bubble_height); 217 font_list.DeriveWithHeightUpperBound(bubble_height);
224 218
225 const SkColor background_color = 219 const SkColor background_color = GetColor(LocationBarView::BACKGROUND);
226 GetColor(SecurityStateModel::NONE, LocationBarView::BACKGROUND);
227 const SkColor ev_text_color = 220 const SkColor ev_text_color =
228 GetColor(SecurityStateModel::EV_SECURE, SECURITY_TEXT); 221 GetSecureTextColor(SecurityStateModel::EV_SECURE);
229 ev_bubble_view_ = 222 ev_bubble_view_ =
230 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this); 223 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this);
231 ev_bubble_view_->set_drag_controller(this); 224 ev_bubble_view_->set_drag_controller(this);
232 AddChildView(ev_bubble_view_); 225 AddChildView(ev_bubble_view_);
233 226
234 // Initialize the Omnibox view. 227 // Initialize the Omnibox view.
235 omnibox_view_ = new OmniboxViewViews( 228 omnibox_view_ = new OmniboxViewViews(
236 this, profile(), command_updater(), is_popup_mode_, this, font_list); 229 this, profile(), command_updater(), is_popup_mode_, this, font_list);
237 omnibox_view_->Init(); 230 omnibox_view_->Init();
238 omnibox_view_->SetFocusable(true); 231 omnibox_view_->SetFocusable(true);
239 AddChildView(omnibox_view_); 232 AddChildView(omnibox_view_);
240 233
241 // Initialize the inline autocomplete view which is visible only when IME is 234 // Initialize the inline autocomplete view which is visible only when IME is
242 // turned on. Use the same font with the omnibox and highlighted background. 235 // turned on. Use the same font with the omnibox and highlighted background.
243 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); 236 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list);
244 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 237 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
245 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 238 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
246 ime_inline_autocomplete_view_->set_background( 239 ime_inline_autocomplete_view_->set_background(
247 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 240 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 241 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
249 ime_inline_autocomplete_view_->SetEnabledColor( 242 ime_inline_autocomplete_view_->SetEnabledColor(
250 GetNativeTheme()->GetSystemColor( 243 GetNativeTheme()->GetSystemColor(
251 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 244 ui::NativeTheme::kColorId_TextfieldSelectionColor));
252 ime_inline_autocomplete_view_->SetVisible(false); 245 ime_inline_autocomplete_view_->SetVisible(false);
253 AddChildView(ime_inline_autocomplete_view_); 246 AddChildView(ime_inline_autocomplete_view_);
254 247
255 const SkColor selected_text_color = GetColor(SecurityStateModel::NONE, TEXT); 248 const SkColor selected_text_color = GetColor(TEXT);
256 selected_keyword_view_ = new SelectedKeywordView( 249 selected_keyword_view_ = new SelectedKeywordView(
257 bubble_font_list, selected_text_color, background_color, profile()); 250 bubble_font_list, selected_text_color, background_color, profile());
258 AddChildView(selected_keyword_view_); 251 AddChildView(selected_keyword_view_);
259 252
260 suggested_text_view_ = new views::Label(base::string16(), font_list); 253 suggested_text_view_ = new views::Label(base::string16(), font_list);
261 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 254 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
262 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 255 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
263 suggested_text_view_->SetEnabledColor( 256 suggested_text_view_->SetEnabledColor(
264 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 257 GetColor(LocationBarView::DEEMPHASIZED_TEXT));
265 suggested_text_view_->SetVisible(false); 258 suggested_text_view_->SetVisible(false);
266 AddChildView(suggested_text_view_); 259 AddChildView(suggested_text_view_);
267 260
268 keyword_hint_view_ = new KeywordHintView( 261 keyword_hint_view_ = new KeywordHintView(
269 profile(), font_list, bubble_font_list, 262 profile(), font_list, bubble_font_list,
270 bubble_height + 2 * kBubbleInteriorVerticalPadding, 263 bubble_height + 2 * kBubbleInteriorVerticalPadding,
271 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), 264 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
272 background_color);
273 AddChildView(keyword_hint_view_); 265 AddChildView(keyword_hint_view_);
274 266
275 const SkColor text_color = GetColor(SecurityStateModel::NONE, TEXT); 267 const SkColor text_color = GetColor(TEXT);
276 ScopedVector<ContentSettingImageModel> models = 268 ScopedVector<ContentSettingImageModel> models =
277 ContentSettingImageModel::GenerateContentSettingImageModels(); 269 ContentSettingImageModel::GenerateContentSettingImageModels();
278 for (ContentSettingImageModel* model : models.get()) { 270 for (ContentSettingImageModel* model : models.get()) {
279 // ContentSettingImageView takes ownership of its model. 271 // ContentSettingImageView takes ownership of its model.
280 ContentSettingImageView* image_view = new ContentSettingImageView( 272 ContentSettingImageView* image_view = new ContentSettingImageView(
281 model, this, bubble_font_list, text_color, background_color); 273 model, this, bubble_font_list, text_color, background_color);
282 content_setting_views_.push_back(image_view); 274 content_setting_views_.push_back(image_view);
283 image_view->SetVisible(false); 275 image_view->SetVisible(false);
284 AddChildView(image_view); 276 AddChildView(image_view);
285 } 277 }
(...skipping 26 matching lines...) Expand all
312 Update(NULL); 304 Update(NULL);
313 305
314 size_animation_.Reset(1); 306 size_animation_.Reset(1);
315 } 307 }
316 308
317 bool LocationBarView::IsInitialized() const { 309 bool LocationBarView::IsInitialized() const {
318 return omnibox_view_ != NULL; 310 return omnibox_view_ != NULL;
319 } 311 }
320 312
321 SkColor LocationBarView::GetColor( 313 SkColor LocationBarView::GetColor(
322 SecurityStateModel::SecurityLevel security_level,
323 ColorKind kind) const { 314 ColorKind kind) const {
324 const ui::NativeTheme* native_theme = GetNativeTheme(); 315 const ui::NativeTheme* native_theme = GetNativeTheme();
325 switch (kind) { 316 switch (kind) {
326 case BACKGROUND: 317 case BACKGROUND:
327 return native_theme->GetSystemColor( 318 return native_theme->GetSystemColor(
328 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 319 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
329 320
330 case TEXT: 321 case TEXT:
331 return native_theme->GetSystemColor( 322 return native_theme->GetSystemColor(
332 ui::NativeTheme::kColorId_TextfieldDefaultColor); 323 ui::NativeTheme::kColorId_TextfieldDefaultColor);
333 324
334 case SELECTED_TEXT: 325 case SELECTED_TEXT:
335 return native_theme->GetSystemColor( 326 return native_theme->GetSystemColor(
336 ui::NativeTheme::kColorId_TextfieldSelectionColor); 327 ui::NativeTheme::kColorId_TextfieldSelectionColor);
337 328
338 case DEEMPHASIZED_TEXT: 329 case DEEMPHASIZED_TEXT:
339 return color_utils::AlphaBlend( 330 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);
340 GetColor(security_level, TEXT), 331 }
341 GetColor(security_level, BACKGROUND), 332 NOTREACHED();
342 128); 333 return gfx::kPlaceholderColor;
334 }
343 335
344 case SECURITY_TEXT: { 336 SkColor LocationBarView::GetSecureTextColor(
345 SkColor color; 337 SecurityStateModel::SecurityLevel security_level) const {
346 switch (security_level) { 338 bool inverted =
347 case SecurityStateModel::EV_SECURE: 339 color_utils::GetLuminanceForColor(GetColor(BACKGROUND)) >= 128;
348 case SecurityStateModel::SECURE: 340 SkColor color;
349 color = ui::MaterialDesignController::IsModeMaterial() ? 341 switch (security_level) {
350 gfx::kGoogleGreen700 : SkColorSetRGB(7, 149, 0); 342 case SecurityStateModel::EV_SECURE:
351 break; 343 case SecurityStateModel::SECURE:
344 color = ui::MaterialDesignController::IsModeMaterial()
345 ? inverted ? gfx::kGoogleGreen300 : gfx::kGoogleGreen700
346 : SkColorSetRGB(7, 149, 0);
347 break;
352 348
353 case SecurityStateModel::SECURITY_POLICY_WARNING: 349 case SecurityStateModel::SECURITY_POLICY_WARNING:
354 return GetColor(security_level, DEEMPHASIZED_TEXT); 350 return GetColor(DEEMPHASIZED_TEXT);
355 break; 351 break;
356 352
357 case SecurityStateModel::SECURITY_ERROR: 353 case SecurityStateModel::SECURITY_ERROR:
358 color = ui::MaterialDesignController::IsModeMaterial() ? 354 color = ui::MaterialDesignController::IsModeMaterial()
359 gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); 355 ? inverted ? gfx::kGoogleRed300 : gfx::kGoogleRed700
360 break; 356 : SkColorSetRGB(162, 0, 0);
357 break;
361 358
362 case SecurityStateModel::SECURITY_WARNING: 359 case SecurityStateModel::SECURITY_WARNING:
363 return GetColor(security_level, TEXT); 360 return GetColor(TEXT);
364 break; 361 break;
365
366 default:
367 NOTREACHED();
368 return GetColor(security_level, TEXT);
369 }
370 return color_utils::GetReadableColor(
371 color, GetColor(security_level, BACKGROUND));
372 }
373 362
374 default: 363 default:
375 NOTREACHED(); 364 NOTREACHED();
376 return GetColor(security_level, TEXT); 365 return gfx::kPlaceholderColor;
377 } 366 }
367 return color_utils::GetReadableColor(color, GetColor(BACKGROUND));
378 } 368 }
379 369
380 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 370 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
381 DCHECK(zoom_view_); 371 DCHECK(zoom_view_);
382 if (RefreshZoomView()) { 372 if (RefreshZoomView()) {
383 Layout(); 373 Layout();
384 SchedulePaint(); 374 SchedulePaint();
385 } 375 }
386 376
387 WebContents* web_contents = GetWebContents(); 377 WebContents* web_contents = GetWebContents();
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 else if (location_needed_width + width > entry_width) 775 else if (location_needed_width + width > entry_width)
786 x = entry_width - width; 776 x = entry_width - width;
787 location_bounds.set_width(x); 777 location_bounds.set_width(x);
788 ime_inline_autocomplete_view_->SetBounds( 778 ime_inline_autocomplete_view_->SetBounds(
789 location_bounds.right(), location_bounds.y(), 779 location_bounds.right(), location_bounds.y(),
790 std::min(width, entry_width), location_bounds.height()); 780 std::min(width, entry_width), location_bounds.height());
791 } 781 }
792 omnibox_view_->SetBoundsRect(location_bounds); 782 omnibox_view_->SetBoundsRect(location_bounds);
793 } 783 }
794 784
785 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
786 if (!ui::MaterialDesignController::IsModeMaterial())
787 return;
788
789 set_background(new BackgroundWith1PxBorder(
790 GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00),
791 is_popup_mode_));
792 }
793
795 void LocationBarView::Update(const WebContents* contents) { 794 void LocationBarView::Update(const WebContents* contents) {
796 RefreshContentSettingViews(); 795 RefreshContentSettingViews();
797 RefreshZoomView(); 796 RefreshZoomView();
798 RefreshPageActionViews(); 797 RefreshPageActionViews();
799 RefreshTranslateIcon(); 798 RefreshTranslateIcon();
800 RefreshSaveCreditCardIconView(); 799 RefreshSaveCreditCardIconView();
801 RefreshManagePasswordsIconView(); 800 RefreshManagePasswordsIconView();
802 content::WebContents* web_contents_for_sub_views = 801 content::WebContents* web_contents_for_sub_views =
803 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); 802 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents();
804 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 803 open_pdf_in_reader_view_->Update(web_contents_for_sub_views);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 View::OnPaint(canvas); 1253 View::OnPaint(canvas);
1255 1254
1256 if (ui::MaterialDesignController::IsModeMaterial()) 1255 if (ui::MaterialDesignController::IsModeMaterial())
1257 return; // The background and border are painted by our Background. 1256 return; // The background and border are painted by our Background.
1258 1257
1259 // Fill the location bar background color behind the border. Parts of the 1258 // Fill the location bar background color behind the border. Parts of the
1260 // border images are meant to rest atop the toolbar background and parts atop 1259 // border images are meant to rest atop the toolbar background and parts atop
1261 // the omnibox background, so we can't just blindly fill our entire bounds. 1260 // the omnibox background, so we can't just blindly fill our entire bounds.
1262 gfx::Rect bounds(GetContentsBounds()); 1261 gfx::Rect bounds(GetContentsBounds());
1263 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1262 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
1264 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); 1263 SkColor color(GetColor(BACKGROUND));
1265 if (is_popup_mode_) { 1264 if (is_popup_mode_) {
1266 canvas->FillRect(bounds, color); 1265 canvas->FillRect(bounds, color);
1267 } else { 1266 } else {
1268 SkPaint paint; 1267 SkPaint paint;
1269 paint.setStyle(SkPaint::kFill_Style); 1268 paint.setStyle(SkPaint::kFill_Style);
1270 paint.setColor(color); 1269 paint.setColor(color);
1271 const int kBorderCornerRadius = 2; 1270 const int kBorderCornerRadius = 2;
1272 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1271 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1273 } 1272 }
1274 1273
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 // LocationBarView, private TemplateURLServiceObserver implementation: 1385 // LocationBarView, private TemplateURLServiceObserver implementation:
1387 1386
1388 void LocationBarView::OnTemplateURLServiceChanged() { 1387 void LocationBarView::OnTemplateURLServiceChanged() {
1389 template_url_service_->RemoveObserver(this); 1388 template_url_service_->RemoveObserver(this);
1390 template_url_service_ = NULL; 1389 template_url_service_ = NULL;
1391 // If the browser is no longer active, let's not show the info bubble, as this 1390 // If the browser is no longer active, let's not show the info bubble, as this
1392 // would make the browser the active window again. 1391 // would make the browser the active window again.
1393 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1392 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1394 ShowFirstRunBubble(); 1393 ShowFirstRunBubble();
1395 } 1394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698