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

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

Issue 1394763003: Update LocationBarView Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 20 matching lines...) Expand all
31 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_finder.h" 32 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_instant_controller.h" 33 #include "chrome/browser/ui/browser_instant_controller.h"
34 #include "chrome/browser/ui/browser_window.h" 34 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 35 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 36 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
37 #include "chrome/browser/ui/tabs/tab_strip_model.h" 37 #include "chrome/browser/ui/tabs/tab_strip_model.h"
38 #include "chrome/browser/ui/view_ids.h" 38 #include "chrome/browser/ui/view_ids.h"
39 #include "chrome/browser/ui/views/browser_dialogs.h" 39 #include "chrome/browser/ui/views/browser_dialogs.h"
40 #include "chrome/browser/ui/views/layout_constants.h" 40 #include "chrome/browser/ui/views/layout_constants.h"
41 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 42 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 43 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
49 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h" 50 #include "chrome/browser/ui/views/location_bar/save_credit_card_icon_view.h"
50 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return base::i18n::IsRTL() ? 1 : 0; 110 return base::i18n::IsRTL() ? 1 : 0;
110 } 111 }
111 112
112 } // namespace 113 } // namespace
113 114
114 115
115 // LocationBarView ----------------------------------------------------------- 116 // LocationBarView -----------------------------------------------------------
116 117
117 // static 118 // static
118 119
119 // TODO(jonross): Replace with lookup once Material Design asset has landed. 120 // Thickness of the edges of the omnibox background images, for popup windows.
120 // (https://crbug.com/495654)
121 // Thickness of the edges of the omnibox background images, for normal and
122 // popup windows.
123 const int kNormalEdgeThickness = 2;
124 const int kPopupEdgeThickness = 1; 121 const int kPopupEdgeThickness = 1;
125 122
126 const char LocationBarView::kViewClassName[] = "LocationBarView"; 123 const char LocationBarView::kViewClassName[] = "LocationBarView";
127 124
128 LocationBarView::LocationBarView(Browser* browser, 125 LocationBarView::LocationBarView(Browser* browser,
129 Profile* profile, 126 Profile* profile,
130 CommandUpdater* command_updater, 127 CommandUpdater* command_updater,
131 Delegate* delegate, 128 Delegate* delegate,
132 bool is_popup_mode) 129 bool is_popup_mode)
133 : LocationBar(profile), 130 : LocationBar(profile),
(...skipping 23 matching lines...) Expand all
157 edit_bookmarks_enabled_.Init( 154 edit_bookmarks_enabled_.Init(
158 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), 155 bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
159 base::Bind(&LocationBarView::UpdateWithoutTabRestore, 156 base::Bind(&LocationBarView::UpdateWithoutTabRestore,
160 base::Unretained(this))); 157 base::Unretained(this)));
161 158
162 if (browser_) 159 if (browser_)
163 browser_->search_model()->AddObserver(this); 160 browser_->search_model()->AddObserver(this);
164 161
165 ui_zoom::ZoomEventManager::GetForBrowserContext(profile) 162 ui_zoom::ZoomEventManager::GetForBrowserContext(profile)
166 ->AddZoomEventManagerObserver(this); 163 ->AddZoomEventManagerObserver(this);
164
165 if (ui::MaterialDesignController::IsModeMaterial()) {
166 set_background(new BackgroundWith1PxBorder(
167 GetColor(SecurityStateModel::NONE, BACKGROUND),
168 SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), !is_popup_mode_));
169 }
167 } 170 }
168 171
169 LocationBarView::~LocationBarView() { 172 LocationBarView::~LocationBarView() {
170 if (template_url_service_) 173 if (template_url_service_)
171 template_url_service_->RemoveObserver(this); 174 template_url_service_->RemoveObserver(this);
172 if (browser_) 175 if (browser_)
173 browser_->search_model()->RemoveObserver(this); 176 browser_->search_model()->RemoveObserver(this);
174 177
175 ui_zoom::ZoomEventManager::GetForBrowserContext(profile()) 178 ui_zoom::ZoomEventManager::GetForBrowserContext(profile())
176 ->RemoveZoomEventManagerObserver(this); 179 ->RemoveZoomEventManagerObserver(this);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 gfx::Point* top_left_screen_coord, 509 gfx::Point* top_left_screen_coord,
507 int* popup_width, 510 int* popup_width,
508 int* left_margin, 511 int* left_margin,
509 int* right_margin, 512 int* right_margin,
510 int top_edge_overlap) { 513 int top_edge_overlap) {
511 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap); 514 *top_left_screen_coord = gfx::Point(0, parent()->height() - top_edge_overlap);
512 views::View::ConvertPointToScreen(parent(), top_left_screen_coord); 515 views::View::ConvertPointToScreen(parent(), top_left_screen_coord);
513 516
514 *popup_width = parent()->width(); 517 *popup_width = parent()->width();
515 gfx::Rect location_bar_bounds(bounds()); 518 gfx::Rect location_bar_bounds(bounds());
516 location_bar_bounds.Inset(kNormalEdgeThickness, 0); 519 location_bar_bounds.Inset(GetLayoutConstant(LOCATION_BAR_EDGE_THICKNESS), 0);
517 *left_margin = location_bar_bounds.x(); 520 *left_margin = location_bar_bounds.x();
518 *right_margin = *popup_width - location_bar_bounds.right(); 521 *right_margin = *popup_width - location_bar_bounds.right();
519 } 522 }
520 523
521 //////////////////////////////////////////////////////////////////////////////// 524 ////////////////////////////////////////////////////////////////////////////////
522 // LocationBarView, public LocationBar implementation: 525 // LocationBarView, public LocationBar implementation:
523 526
524 void LocationBarView::FocusLocation(bool select_all) { 527 void LocationBarView::FocusLocation(bool select_all) {
525 omnibox_view_->SetFocus(); 528 omnibox_view_->SetFocus();
526 if (select_all) 529 if (select_all)
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 } 881 }
879 882
880 int LocationBarView::GetHorizontalEdgeThickness() const { 883 int LocationBarView::GetHorizontalEdgeThickness() const {
881 // In maximized popup mode, there isn't any edge. 884 // In maximized popup mode, there isn't any edge.
882 return (is_popup_mode_ && browser_ && browser_->window() && 885 return (is_popup_mode_ && browser_ && browser_->window() &&
883 browser_->window()->IsMaximized()) ? 886 browser_->window()->IsMaximized()) ?
884 0 : GetVerticalEdgeThickness(); 887 0 : GetVerticalEdgeThickness();
885 } 888 }
886 889
887 int LocationBarView::GetVerticalEdgeThickness() const { 890 int LocationBarView::GetVerticalEdgeThickness() const {
888 // In Material Design vertical layout disregards the border. 891 return is_popup_mode_ ? kPopupEdgeThickness
889 if (ui::MaterialDesignController::IsModeMaterial()) 892 : GetLayoutConstant(LOCATION_BAR_EDGE_THICKNESS);
890 return 0;
891 return is_popup_mode_ ? kPopupEdgeThickness : kNormalEdgeThickness;
892 } 893 }
893 894
894 int LocationBarView::VerticalPadding() const { 895 int LocationBarView::VerticalPadding() const {
895 return is_popup_mode_ ? 896 return is_popup_mode_ ?
896 kPopupEdgeThickness : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); 897 kPopupEdgeThickness : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
897 } 898 }
898 899
899 bool LocationBarView::RefreshContentSettingViews() { 900 bool LocationBarView::RefreshContentSettingViews() {
900 bool visibility_changed = false; 901 bool visibility_changed = false;
901 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 902 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 1283
1283 void LocationBarView::OnFocus() { 1284 void LocationBarView::OnFocus() {
1284 // Explicitly focus the omnibox so a focus ring will be displayed around it on 1285 // Explicitly focus the omnibox so a focus ring will be displayed around it on
1285 // Windows. 1286 // Windows.
1286 omnibox_view_->SetFocus(); 1287 omnibox_view_->SetFocus();
1287 } 1288 }
1288 1289
1289 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1290 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1290 View::OnPaint(canvas); 1291 View::OnPaint(canvas);
1291 1292
1293 if (ui::MaterialDesignController::IsModeMaterial())
1294 return; // The background and border are painted by our Background.
1295
1292 // Fill the location bar background color behind the border. Parts of the 1296 // Fill the location bar background color behind the border. Parts of the
1293 // border images are meant to rest atop the toolbar background and parts atop 1297 // border images are meant to rest atop the toolbar background and parts atop
1294 // the omnibox background, so we can't just blindly fill our entire bounds. 1298 // the omnibox background, so we can't just blindly fill our entire bounds.
1295 gfx::Rect bounds(GetContentsBounds()); 1299 gfx::Rect bounds(GetContentsBounds());
1296 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1300 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
1297 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); 1301 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND));
1298 if (is_popup_mode_) { 1302 if (is_popup_mode_) {
1299 canvas->FillRect(bounds, color); 1303 canvas->FillRect(bounds, color);
1300 } else { 1304 } else {
1301 SkPaint paint; 1305 SkPaint paint;
(...skipping 12 matching lines...) Expand all
1314 1318
1315 ui::PaintRecorder recorder(context, size()); 1319 ui::PaintRecorder recorder(context, size());
1316 1320
1317 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need 1321 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need
1318 // the focus rect to appear on top of children we paint here rather than 1322 // the focus rect to appear on top of children we paint here rather than
1319 // OnPaint(). 1323 // OnPaint().
1320 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. 1324 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color.
1321 if (show_focus_rect_ && HasFocus()) 1325 if (show_focus_rect_ && HasFocus())
1322 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); 1326 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds());
1323 1327
1328 if (ui::MaterialDesignController::IsModeMaterial())
1329 return; // The background and border are painted by our Background.
1330
1324 // Maximized popup windows don't draw the horizontal edges. We implement this 1331 // Maximized popup windows don't draw the horizontal edges. We implement this
1325 // by simply expanding the paint area outside the view by the edge thickness. 1332 // by simply expanding the paint area outside the view by the edge thickness.
1326 gfx::Rect border_rect(GetContentsBounds()); 1333 gfx::Rect border_rect(GetContentsBounds());
1327 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) 1334 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0))
1328 border_rect.Inset(-kPopupEdgeThickness, 0); 1335 border_rect.Inset(-kPopupEdgeThickness, 0);
1329 1336 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1330 if (ui::MaterialDesignController::IsModeMaterial()) { 1337 border_rect);
1331 gfx::Canvas* canvas = recorder.canvas();
1332 const float scale = canvas->SaveAndUnscale();
1333
1334 SkPaint paint;
1335 paint.setStyle(SkPaint::Style::kStroke_Style);
1336 paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00));
1337 paint.setStrokeWidth(1);
1338 paint.setAntiAlias(true);
1339
1340 const float kOffset = 0.5f;
1341 gfx::RectF border_rect_f(border_rect);
1342 border_rect_f.Scale(scale);
1343 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
1344 border_rect_f.Inset(insets);
1345
1346 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * scale);
1347 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f),
1348 kCornerRadius, kCornerRadius, paint);
1349 recorder.canvas()->Restore();
1350 } else {
1351 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1352 border_rect);
1353 }
1354 } 1338 }
1355 1339
1356 //////////////////////////////////////////////////////////////////////////////// 1340 ////////////////////////////////////////////////////////////////////////////////
1357 // LocationBarView, private views::ButtonListener implementation: 1341 // LocationBarView, private views::ButtonListener implementation:
1358 1342
1359 void LocationBarView::ButtonPressed(views::Button* sender, 1343 void LocationBarView::ButtonPressed(views::Button* sender,
1360 const ui::Event& event) { 1344 const ui::Event& event) {
1361 DCHECK_EQ(mic_search_view_, sender); 1345 DCHECK_EQ(mic_search_view_, sender);
1362 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); 1346 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT);
1363 } 1347 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 1441
1458 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1442 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1459 const SearchModel::State& new_state) { 1443 const SearchModel::State& new_state) {
1460 const bool visible = !GetToolbarModel()->input_in_progress() && 1444 const bool visible = !GetToolbarModel()->input_in_progress() &&
1461 new_state.voice_search_supported; 1445 new_state.voice_search_supported;
1462 if (mic_search_view_->visible() != visible) { 1446 if (mic_search_view_->visible() != visible) {
1463 mic_search_view_->SetVisible(visible); 1447 mic_search_view_->SetVisible(visible);
1464 Layout(); 1448 Layout();
1465 } 1449 }
1466 } 1450 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698