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

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: iterate on chips 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); 220 const SkColor ev_text_color = GetColor(EV_BUBBLE_TEXT_AND_BORDER);
227 const SkColor ev_text_color =
228 GetColor(SecurityStateModel::EV_SECURE, SECURITY_TEXT);
229 ev_bubble_view_ = 221 ev_bubble_view_ =
230 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this); 222 new EVBubbleView(bubble_font_list, ev_text_color, background_color, this);
231 ev_bubble_view_->set_drag_controller(this); 223 ev_bubble_view_->set_drag_controller(this);
232 AddChildView(ev_bubble_view_); 224 AddChildView(ev_bubble_view_);
233 225
234 // Initialize the Omnibox view. 226 // Initialize the Omnibox view.
235 omnibox_view_ = new OmniboxViewViews( 227 omnibox_view_ = new OmniboxViewViews(
236 this, profile(), command_updater(), is_popup_mode_, this, font_list); 228 this, profile(), command_updater(), is_popup_mode_, this, font_list);
237 omnibox_view_->Init(); 229 omnibox_view_->Init();
238 omnibox_view_->SetFocusable(true); 230 omnibox_view_->SetFocusable(true);
239 AddChildView(omnibox_view_); 231 AddChildView(omnibox_view_);
240 232
241 // Initialize the inline autocomplete view which is visible only when IME is 233 // 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. 234 // turned on. Use the same font with the omnibox and highlighted background.
243 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); 235 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list);
244 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 236 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
245 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 237 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
246 ime_inline_autocomplete_view_->set_background( 238 ime_inline_autocomplete_view_->set_background(
247 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 239 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
248 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 240 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
249 ime_inline_autocomplete_view_->SetEnabledColor( 241 ime_inline_autocomplete_view_->SetEnabledColor(
250 GetNativeTheme()->GetSystemColor( 242 GetNativeTheme()->GetSystemColor(
251 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 243 ui::NativeTheme::kColorId_TextfieldSelectionColor));
252 ime_inline_autocomplete_view_->SetVisible(false); 244 ime_inline_autocomplete_view_->SetVisible(false);
253 AddChildView(ime_inline_autocomplete_view_); 245 AddChildView(ime_inline_autocomplete_view_);
254 246
255 const SkColor selected_text_color = GetColor(SecurityStateModel::NONE, TEXT); 247 const SkColor selected_text_color = GetColor(TEXT);
256 selected_keyword_view_ = new SelectedKeywordView( 248 selected_keyword_view_ = new SelectedKeywordView(
257 bubble_font_list, selected_text_color, background_color, profile()); 249 bubble_font_list, selected_text_color, background_color, profile());
258 AddChildView(selected_keyword_view_); 250 AddChildView(selected_keyword_view_);
259 251
260 suggested_text_view_ = new views::Label(base::string16(), font_list); 252 suggested_text_view_ = new views::Label(base::string16(), font_list);
261 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 253 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
262 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 254 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
263 suggested_text_view_->SetEnabledColor( 255 suggested_text_view_->SetEnabledColor(
264 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 256 GetColor(LocationBarView::DEEMPHASIZED_TEXT));
265 suggested_text_view_->SetVisible(false); 257 suggested_text_view_->SetVisible(false);
266 AddChildView(suggested_text_view_); 258 AddChildView(suggested_text_view_);
267 259
268 keyword_hint_view_ = new KeywordHintView( 260 keyword_hint_view_ = new KeywordHintView(
269 profile(), font_list, bubble_font_list, 261 profile(), font_list, bubble_font_list,
270 bubble_height + 2 * kBubbleInteriorVerticalPadding, 262 bubble_height + 2 * kBubbleInteriorVerticalPadding,
271 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), 263 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
272 background_color);
273 AddChildView(keyword_hint_view_); 264 AddChildView(keyword_hint_view_);
274 265
275 const SkColor text_color = GetColor(SecurityStateModel::NONE, TEXT); 266 const SkColor text_color = GetColor(TEXT);
276 ScopedVector<ContentSettingImageModel> models = 267 ScopedVector<ContentSettingImageModel> models =
277 ContentSettingImageModel::GenerateContentSettingImageModels(); 268 ContentSettingImageModel::GenerateContentSettingImageModels();
278 for (ContentSettingImageModel* model : models.get()) { 269 for (ContentSettingImageModel* model : models.get()) {
279 // ContentSettingImageView takes ownership of its model. 270 // ContentSettingImageView takes ownership of its model.
280 ContentSettingImageView* image_view = new ContentSettingImageView( 271 ContentSettingImageView* image_view = new ContentSettingImageView(
281 model, this, bubble_font_list, text_color, background_color); 272 model, this, bubble_font_list, text_color, background_color);
282 content_setting_views_.push_back(image_view); 273 content_setting_views_.push_back(image_view);
283 image_view->SetVisible(false); 274 image_view->SetVisible(false);
284 AddChildView(image_view); 275 AddChildView(image_view);
285 } 276 }
(...skipping 26 matching lines...) Expand all
312 Update(NULL); 303 Update(NULL);
313 304
314 size_animation_.Reset(1); 305 size_animation_.Reset(1);
315 } 306 }
316 307
317 bool LocationBarView::IsInitialized() const { 308 bool LocationBarView::IsInitialized() const {
318 return omnibox_view_ != NULL; 309 return omnibox_view_ != NULL;
319 } 310 }
320 311
321 SkColor LocationBarView::GetColor( 312 SkColor LocationBarView::GetColor(
322 SecurityStateModel::SecurityLevel security_level,
323 ColorKind kind) const { 313 ColorKind kind) const {
324 const ui::NativeTheme* native_theme = GetNativeTheme(); 314 const ui::NativeTheme* native_theme = GetNativeTheme();
325 switch (kind) { 315 switch (kind) {
326 case BACKGROUND: 316 case BACKGROUND:
327 return native_theme->GetSystemColor( 317 return native_theme->GetSystemColor(
328 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 318 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
329 319
330 case TEXT: 320 case TEXT:
331 return native_theme->GetSystemColor( 321 return native_theme->GetSystemColor(
332 ui::NativeTheme::kColorId_TextfieldDefaultColor); 322 ui::NativeTheme::kColorId_TextfieldDefaultColor);
333 323
334 case SELECTED_TEXT: 324 case SELECTED_TEXT:
335 return native_theme->GetSystemColor( 325 return native_theme->GetSystemColor(
336 ui::NativeTheme::kColorId_TextfieldSelectionColor); 326 ui::NativeTheme::kColorId_TextfieldSelectionColor);
337 327
338 case DEEMPHASIZED_TEXT: 328 case DEEMPHASIZED_TEXT:
339 return color_utils::AlphaBlend( 329 return color_utils::AlphaBlend(GetColor(TEXT), GetColor(BACKGROUND), 128);
340 GetColor(security_level, TEXT),
341 GetColor(security_level, BACKGROUND),
342 128);
343 330
344 case SECURITY_TEXT: { 331 case EV_BUBBLE_TEXT_AND_BORDER:
345 SkColor color; 332 return ui::MaterialDesignController::IsModeMaterial()
346 switch (security_level) { 333 ? gfx::kGoogleGreen700
347 case SecurityStateModel::EV_SECURE: 334 : SkColorSetRGB(7, 149, 0);
Peter Kasting 2015/11/14 02:46:08 I think you need to call GetReadableColor(..., Get
Evan Stade 2015/11/16 19:36:32 This color is not used for text on top of the loca
348 case SecurityStateModel::SECURE: 335 }
349 color = ui::MaterialDesignController::IsModeMaterial() ? 336 NOTREACHED();
350 gfx::kGoogleGreen700 : SkColorSetRGB(7, 149, 0); 337 return gfx::kPlaceholderColor;
351 break; 338 }
352 339
353 case SecurityStateModel::SECURITY_POLICY_WARNING: 340 SkColor LocationBarView::GetSecureTextColor(
354 return GetColor(security_level, DEEMPHASIZED_TEXT); 341 SecurityStateModel::SecurityLevel security_level) const {
355 break; 342 bool inverted =
343 color_utils::GetLuminanceForColor(GetColor(BACKGROUND)) < 128;
344 SkColor color;
345 switch (security_level) {
346 case SecurityStateModel::EV_SECURE:
347 case SecurityStateModel::SECURE:
348 return ui::MaterialDesignController::IsModeMaterial() && inverted
349 ? GetColor(TEXT)
350 : GetColor(EV_BUBBLE_TEXT_AND_BORDER);
351 break;
356 352
357 case SecurityStateModel::SECURITY_ERROR: 353 case SecurityStateModel::SECURITY_POLICY_WARNING:
358 color = ui::MaterialDesignController::IsModeMaterial() ? 354 return GetColor(DEEMPHASIZED_TEXT);
359 gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); 355 break;
360 break;
361 356
362 case SecurityStateModel::SECURITY_WARNING: 357 case SecurityStateModel::SECURITY_ERROR:
363 return GetColor(security_level, TEXT); 358 color = ui::MaterialDesignController::IsModeMaterial()
364 break; 359 ? inverted ? GetColor(TEXT) : gfx::kGoogleRed700
Peter Kasting 2015/11/14 02:46:08 I like ?:s, but please avoid nesting them...
Evan Stade 2015/11/16 19:36:32 rewrote this, but there are still two cases which
360 : SkColorSetRGB(162, 0, 0);
361 break;
365 362
366 default: 363 case SecurityStateModel::SECURITY_WARNING:
367 NOTREACHED(); 364 return GetColor(TEXT);
368 return GetColor(security_level, TEXT); 365 break;
369 }
370 return color_utils::GetReadableColor(
371 color, GetColor(security_level, BACKGROUND));
372 }
373 366
374 default: 367 default:
375 NOTREACHED(); 368 NOTREACHED();
376 return GetColor(security_level, TEXT); 369 return gfx::kPlaceholderColor;
377 } 370 }
371 return color_utils::GetReadableColor(color, GetColor(BACKGROUND));
378 } 372 }
379 373
380 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { 374 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
381 DCHECK(zoom_view_); 375 DCHECK(zoom_view_);
382 if (RefreshZoomView()) { 376 if (RefreshZoomView()) {
383 Layout(); 377 Layout();
384 SchedulePaint(); 378 SchedulePaint();
385 } 379 }
386 380
387 WebContents* web_contents = GetWebContents(); 381 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) 779 else if (location_needed_width + width > entry_width)
786 x = entry_width - width; 780 x = entry_width - width;
787 location_bounds.set_width(x); 781 location_bounds.set_width(x);
788 ime_inline_autocomplete_view_->SetBounds( 782 ime_inline_autocomplete_view_->SetBounds(
789 location_bounds.right(), location_bounds.y(), 783 location_bounds.right(), location_bounds.y(),
790 std::min(width, entry_width), location_bounds.height()); 784 std::min(width, entry_width), location_bounds.height());
791 } 785 }
792 omnibox_view_->SetBoundsRect(location_bounds); 786 omnibox_view_->SetBoundsRect(location_bounds);
793 } 787 }
794 788
789 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
790 if (!ui::MaterialDesignController::IsModeMaterial())
791 return;
792
793 set_background(new BackgroundWith1PxBorder(
794 GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00),
795 is_popup_mode_));
796 }
797
795 void LocationBarView::Update(const WebContents* contents) { 798 void LocationBarView::Update(const WebContents* contents) {
796 RefreshContentSettingViews(); 799 RefreshContentSettingViews();
797 RefreshZoomView(); 800 RefreshZoomView();
798 RefreshPageActionViews(); 801 RefreshPageActionViews();
799 RefreshTranslateIcon(); 802 RefreshTranslateIcon();
800 RefreshSaveCreditCardIconView(); 803 RefreshSaveCreditCardIconView();
801 RefreshManagePasswordsIconView(); 804 RefreshManagePasswordsIconView();
802 content::WebContents* web_contents_for_sub_views = 805 content::WebContents* web_contents_for_sub_views =
803 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); 806 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents();
804 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); 807 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); 1257 View::OnPaint(canvas);
1255 1258
1256 if (ui::MaterialDesignController::IsModeMaterial()) 1259 if (ui::MaterialDesignController::IsModeMaterial())
1257 return; // The background and border are painted by our Background. 1260 return; // The background and border are painted by our Background.
1258 1261
1259 // Fill the location bar background color behind the border. Parts of the 1262 // 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 1263 // 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. 1264 // the omnibox background, so we can't just blindly fill our entire bounds.
1262 gfx::Rect bounds(GetContentsBounds()); 1265 gfx::Rect bounds(GetContentsBounds());
1263 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1266 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
1264 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); 1267 SkColor color(GetColor(BACKGROUND));
1265 if (is_popup_mode_) { 1268 if (is_popup_mode_) {
1266 canvas->FillRect(bounds, color); 1269 canvas->FillRect(bounds, color);
1267 } else { 1270 } else {
1268 SkPaint paint; 1271 SkPaint paint;
1269 paint.setStyle(SkPaint::kFill_Style); 1272 paint.setStyle(SkPaint::kFill_Style);
1270 paint.setColor(color); 1273 paint.setColor(color);
1271 const int kBorderCornerRadius = 2; 1274 const int kBorderCornerRadius = 2;
1272 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1275 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1273 } 1276 }
1274 1277
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 // LocationBarView, private TemplateURLServiceObserver implementation: 1389 // LocationBarView, private TemplateURLServiceObserver implementation:
1387 1390
1388 void LocationBarView::OnTemplateURLServiceChanged() { 1391 void LocationBarView::OnTemplateURLServiceChanged() {
1389 template_url_service_->RemoveObserver(this); 1392 template_url_service_->RemoveObserver(this);
1390 template_url_service_ = NULL; 1393 template_url_service_ = NULL;
1391 // If the browser is no longer active, let's not show the info bubble, as this 1394 // 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. 1395 // would make the browser the active window again.
1393 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1396 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1394 ShowFirstRunBubble(); 1397 ShowFirstRunBubble();
1395 } 1398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698