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

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

Issue 2673503002: Slightly simplify location bar bg/border painting. (Closed)
Patch Set: no functional change Created 3 years, 10 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 #if !defined(OS_CHROMEOS) 99 #if !defined(OS_CHROMEOS)
100 #include "chrome/browser/ui/views/first_run_bubble.h" 100 #include "chrome/browser/ui/views/first_run_bubble.h"
101 #endif 101 #endif
102 102
103 using content::WebContents; 103 using content::WebContents;
104 using views::View; 104 using views::View;
105 105
106 namespace { 106 namespace {
107 107
108 // The border color for MD windows, as well as non-MD popup windows. 108 // The border color and opacity.
109 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D); 109 const SkColor kBorderColor = SK_ColorBLACK;
110 const SkAlpha kBorderOpacity = 0x4D;
110 111
111 } // namespace 112 } // namespace
112 113
113
114 // LocationBarView ----------------------------------------------------------- 114 // LocationBarView -----------------------------------------------------------
115 115
116 // static 116 // static
117 const char LocationBarView::kViewClassName[] = "LocationBarView"; 117 const char LocationBarView::kViewClassName[] = "LocationBarView";
118 118
119 LocationBarView::LocationBarView(Browser* browser, 119 LocationBarView::LocationBarView(Browser* browser,
120 Profile* profile, 120 Profile* profile,
121 CommandUpdater* command_updater, 121 CommandUpdater* command_updater,
122 Delegate* delegate, 122 Delegate* delegate,
123 bool is_popup_mode) 123 bool is_popup_mode)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 template_url_service_->RemoveObserver(this); 155 template_url_service_->RemoveObserver(this);
156 156
157 zoom::ZoomEventManager::GetForBrowserContext(profile()) 157 zoom::ZoomEventManager::GetForBrowserContext(profile())
158 ->RemoveZoomEventManagerObserver(this); 158 ->RemoveZoomEventManagerObserver(this);
159 } 159 }
160 160
161 //////////////////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////////////////
162 // LocationBarView, public: 162 // LocationBarView, public:
163 163
164 // static 164 // static
165 SkColor LocationBarView::GetBorderColor(bool incognito) { 165 SkColor LocationBarView::GetOpaqueBorderColor(bool incognito) {
166 return color_utils::AlphaBlend( 166 return color_utils::AlphaBlend(kBorderColor,
167 SkColorSetA(kBorderColor, SK_AlphaOPAQUE), 167 ThemeProperties::GetDefaultColor(
168 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, 168 ThemeProperties::COLOR_TOOLBAR, incognito),
169 incognito), 169 kBorderOpacity);
Peter Kasting 2017/02/02 00:51:35 Even simpler: Leave kBorderColor as partly-transpa
Evan Stade 2017/02/02 22:39:42 Done.
170 SkColorGetA(kBorderColor));
171 } 170 }
172 171
173 void LocationBarView::Init() { 172 void LocationBarView::Init() {
174 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're 173 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're
175 // not prepared for that. 174 // not prepared for that.
176 DCHECK(GetWidget()); 175 DCHECK(GetWidget());
177 176
178 // Make sure children with layers are clipped. See http://crbug.com/589497 177 // Make sure children with layers are clipped. See http://crbug.com/589497
179 SetPaintToLayer(); 178 SetPaintToLayer();
180 layer()->SetFillsBoundsOpaquely(false); 179 layer()->SetFillsBoundsOpaquely(false);
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 location_bounds.set_width(x); 632 location_bounds.set_width(x);
634 ime_inline_autocomplete_view_->SetBounds( 633 ime_inline_autocomplete_view_->SetBounds(
635 location_bounds.right(), location_bounds.y(), 634 location_bounds.right(), location_bounds.y(),
636 std::min(width, entry_width), location_bounds.height()); 635 std::min(width, entry_width), location_bounds.height());
637 } 636 }
638 omnibox_view_->SetBoundsRect(location_bounds); 637 omnibox_view_->SetBoundsRect(location_bounds);
639 } 638 }
640 639
641 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 640 void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
642 RefreshLocationIcon(); 641 RefreshLocationIcon();
643 if (!is_popup_mode_) { 642 if (is_popup_mode_) {
644 set_background( 643 set_background(
645 new BackgroundWith1PxBorder(GetColor(BACKGROUND), kBorderColor)); 644 views::Background::CreateSolidBackground(GetColor(BACKGROUND)));
646 SchedulePaint(); 645 } else {
646 // This border color will be blended on top of the toolbar (which may use an
647 // image in the case of themes).
648 set_background(new BackgroundWith1PxBorder(
649 GetColor(BACKGROUND), SkColorSetA(kBorderColor, kBorderOpacity)));
647 } 650 }
651 SchedulePaint();
648 } 652 }
649 653
650 void LocationBarView::Update(const WebContents* contents) { 654 void LocationBarView::Update(const WebContents* contents) {
651 RefreshContentSettingViews(); 655 RefreshContentSettingViews();
652 RefreshZoomView(); 656 RefreshZoomView();
653 RefreshPageActionViews(); 657 RefreshPageActionViews();
654 RefreshTranslateIcon(); 658 RefreshTranslateIcon();
655 RefreshSaveCreditCardIconView(); 659 RefreshSaveCreditCardIconView();
656 RefreshManagePasswordsIconView(); 660 RefreshManagePasswordsIconView();
657 WebContents* web_contents_for_sub_views = 661 WebContents* web_contents_for_sub_views =
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 paint.setAntiAlias(true); 1145 paint.setAntiAlias(true);
1142 paint.setColor(GetNativeTheme()->GetSystemColor( 1146 paint.setColor(GetNativeTheme()->GetSystemColor(
1143 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); 1147 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor));
1144 paint.setStyle(SkPaint::kStroke_Style); 1148 paint.setStyle(SkPaint::kStroke_Style);
1145 paint.setStrokeWidth(1); 1149 paint.setStrokeWidth(1);
1146 gfx::RectF focus_rect(GetLocalBounds()); 1150 gfx::RectF focus_rect(GetLocalBounds());
1147 focus_rect.Inset(gfx::InsetsF(0.5f)); 1151 focus_rect.Inset(gfx::InsetsF(0.5f));
1148 canvas->DrawRoundRect(focus_rect, 1152 canvas->DrawRoundRect(focus_rect,
1149 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint); 1153 BackgroundWith1PxBorder::kCornerRadius + 0.5f, paint);
1150 } 1154 }
1155 }
1156
1157 void LocationBarView::OnPaintBorder(gfx::Canvas* canvas) {
1151 if (!is_popup_mode_) 1158 if (!is_popup_mode_)
1152 return; // The background and border are painted by our Background. 1159 return; // The border is painted by our Background.
1153 1160
1154 // Fill the location bar background color behind the border. Parts of the
1155 // border images are meant to rest atop the toolbar background and parts atop
1156 // the omnibox background, so we can't just blindly fill our entire bounds.
1157 gfx::Rect bounds(GetContentsBounds()); 1161 gfx::Rect bounds(GetContentsBounds());
1158 bounds.Inset(GetHorizontalEdgeThickness(), 1162 const SkColor border_color =
Evan Stade 2017/02/01 23:58:33 since is_popup_mode_ is true, this was returning 0
1159 is_popup_mode_ 1163 GetOpaqueBorderColor(profile()->IsOffTheRecord());
Evan Stade 2017/02/01 23:58:33 always true
1160 ? 0
1161 : BackgroundWith1PxBorder::kLocationBarBorderThicknessDip);
1162 SkColor background_color(GetColor(BACKGROUND));
1163 canvas->FillRect(bounds, background_color);
1164 const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord());
1165 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false); 1164 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false);
1166 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true); 1165 BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true);
1167 } 1166 }
1168 1167
1169 //////////////////////////////////////////////////////////////////////////////// 1168 ////////////////////////////////////////////////////////////////////////////////
1170 // LocationBarView, private views::DragController implementation: 1169 // LocationBarView, private views::DragController implementation:
1171 1170
1172 void LocationBarView::WriteDragDataForView(views::View* sender, 1171 void LocationBarView::WriteDragDataForView(views::View* sender,
1173 const gfx::Point& press_pt, 1172 const gfx::Point& press_pt,
1174 OSExchangeData* data) { 1173 OSExchangeData* data) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 // LocationBarView, private TemplateURLServiceObserver implementation: 1234 // LocationBarView, private TemplateURLServiceObserver implementation:
1236 1235
1237 void LocationBarView::OnTemplateURLServiceChanged() { 1236 void LocationBarView::OnTemplateURLServiceChanged() {
1238 template_url_service_->RemoveObserver(this); 1237 template_url_service_->RemoveObserver(this);
1239 template_url_service_ = nullptr; 1238 template_url_service_ = nullptr;
1240 // If the browser is no longer active, let's not show the info bubble, as this 1239 // If the browser is no longer active, let's not show the info bubble, as this
1241 // would make the browser the active window again. 1240 // would make the browser the active window again.
1242 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1241 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1243 ShowFirstRunBubble(); 1242 ShowFirstRunBubble();
1244 } 1243 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698