OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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); |
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 if (ui::MaterialDesignController::IsModeMaterial() && inverted) |
| 349 return GetColor(TEXT); |
| 350 color = 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 bool md = ui::MaterialDesignController::IsModeMaterial(); |
364 break; | 359 if (md && inverted) |
| 360 return GetColor(TEXT); |
| 361 color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); |
| 362 break; |
| 363 } |
365 | 364 |
366 default: | 365 case SecurityStateModel::SECURITY_WARNING: |
367 NOTREACHED(); | 366 return GetColor(TEXT); |
368 return GetColor(security_level, TEXT); | 367 break; |
369 } | |
370 return color_utils::GetReadableColor( | |
371 color, GetColor(security_level, BACKGROUND)); | |
372 } | |
373 | 368 |
374 default: | 369 default: |
375 NOTREACHED(); | 370 NOTREACHED(); |
376 return GetColor(security_level, TEXT); | 371 return gfx::kPlaceholderColor; |
377 } | 372 } |
| 373 return color_utils::GetReadableColor(color, GetColor(BACKGROUND)); |
378 } | 374 } |
379 | 375 |
380 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 376 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
381 DCHECK(zoom_view_); | 377 DCHECK(zoom_view_); |
382 if (RefreshZoomView()) { | 378 if (RefreshZoomView()) { |
383 Layout(); | 379 Layout(); |
384 SchedulePaint(); | 380 SchedulePaint(); |
385 } | 381 } |
386 | 382 |
387 WebContents* web_contents = GetWebContents(); | 383 WebContents* web_contents = GetWebContents(); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 else if (location_needed_width + width > entry_width) | 781 else if (location_needed_width + width > entry_width) |
786 x = entry_width - width; | 782 x = entry_width - width; |
787 location_bounds.set_width(x); | 783 location_bounds.set_width(x); |
788 ime_inline_autocomplete_view_->SetBounds( | 784 ime_inline_autocomplete_view_->SetBounds( |
789 location_bounds.right(), location_bounds.y(), | 785 location_bounds.right(), location_bounds.y(), |
790 std::min(width, entry_width), location_bounds.height()); | 786 std::min(width, entry_width), location_bounds.height()); |
791 } | 787 } |
792 omnibox_view_->SetBoundsRect(location_bounds); | 788 omnibox_view_->SetBoundsRect(location_bounds); |
793 } | 789 } |
794 | 790 |
| 791 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 792 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 793 return; |
| 794 |
| 795 set_background(new BackgroundWith1PxBorder( |
| 796 GetColor(BACKGROUND), SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), |
| 797 is_popup_mode_)); |
| 798 } |
| 799 |
795 void LocationBarView::Update(const WebContents* contents) { | 800 void LocationBarView::Update(const WebContents* contents) { |
796 RefreshContentSettingViews(); | 801 RefreshContentSettingViews(); |
797 RefreshZoomView(); | 802 RefreshZoomView(); |
798 RefreshPageActionViews(); | 803 RefreshPageActionViews(); |
799 RefreshTranslateIcon(); | 804 RefreshTranslateIcon(); |
800 RefreshSaveCreditCardIconView(); | 805 RefreshSaveCreditCardIconView(); |
801 RefreshManagePasswordsIconView(); | 806 RefreshManagePasswordsIconView(); |
802 content::WebContents* web_contents_for_sub_views = | 807 content::WebContents* web_contents_for_sub_views = |
803 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); | 808 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents(); |
804 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); | 809 open_pdf_in_reader_view_->Update(web_contents_for_sub_views); |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 View::OnPaint(canvas); | 1259 View::OnPaint(canvas); |
1255 | 1260 |
1256 if (ui::MaterialDesignController::IsModeMaterial()) | 1261 if (ui::MaterialDesignController::IsModeMaterial()) |
1257 return; // The background and border are painted by our Background. | 1262 return; // The background and border are painted by our Background. |
1258 | 1263 |
1259 // Fill the location bar background color behind the border. Parts of the | 1264 // 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 | 1265 // 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. | 1266 // the omnibox background, so we can't just blindly fill our entire bounds. |
1262 gfx::Rect bounds(GetContentsBounds()); | 1267 gfx::Rect bounds(GetContentsBounds()); |
1263 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); | 1268 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); |
1264 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); | 1269 SkColor color(GetColor(BACKGROUND)); |
1265 if (is_popup_mode_) { | 1270 if (is_popup_mode_) { |
1266 canvas->FillRect(bounds, color); | 1271 canvas->FillRect(bounds, color); |
1267 } else { | 1272 } else { |
1268 SkPaint paint; | 1273 SkPaint paint; |
1269 paint.setStyle(SkPaint::kFill_Style); | 1274 paint.setStyle(SkPaint::kFill_Style); |
1270 paint.setColor(color); | 1275 paint.setColor(color); |
1271 const int kBorderCornerRadius = 2; | 1276 const int kBorderCornerRadius = 2; |
1272 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1277 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1273 } | 1278 } |
1274 | 1279 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 // LocationBarView, private TemplateURLServiceObserver implementation: | 1391 // LocationBarView, private TemplateURLServiceObserver implementation: |
1387 | 1392 |
1388 void LocationBarView::OnTemplateURLServiceChanged() { | 1393 void LocationBarView::OnTemplateURLServiceChanged() { |
1389 template_url_service_->RemoveObserver(this); | 1394 template_url_service_->RemoveObserver(this); |
1390 template_url_service_ = NULL; | 1395 template_url_service_ = NULL; |
1391 // If the browser is no longer active, let's not show the info bubble, as this | 1396 // 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. | 1397 // would make the browser the active window again. |
1393 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1398 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
1394 ShowFirstRunBubble(); | 1399 ShowFirstRunBubble(); |
1395 } | 1400 } |
OLD | NEW |