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

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 1826653002: Draw infobar arrow border with width of 1px on any scale factor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 4 years, 8 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/infobars/infobar_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/infobars/infobar_view.h" 5 #include "chrome/browser/ui/views/infobars/infobar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (ui::MaterialDesignController::IsModeMaterial()) { 95 if (ui::MaterialDesignController::IsModeMaterial()) {
96 child_container_->SetPaintToLayer(true); 96 child_container_->SetPaintToLayer(true);
97 child_container_->layer()->SetMasksToBounds(true); 97 child_container_->layer()->SetMasksToBounds(true);
98 // Since MD doesn't use a gradient, we can set a solid bg color. 98 // Since MD doesn't use a gradient, we can set a solid bg color.
99 child_container_->set_background( 99 child_container_->set_background(
100 views::Background::CreateSolidBackground(infobars::InfoBar::GetTopColor( 100 views::Background::CreateSolidBackground(infobars::InfoBar::GetTopColor(
101 infobars::InfoBar::delegate()->GetInfoBarType()))); 101 infobars::InfoBar::delegate()->GetInfoBarType())));
102 } 102 }
103 } 103 }
104 104
105 const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
106 const {
107 const infobars::InfoBarContainer* infobar_container = container();
108 return infobar_container ? infobar_container->delegate() : NULL;
109 }
110
105 InfoBarView::~InfoBarView() { 111 InfoBarView::~InfoBarView() {
106 // We should have closed any open menus in PlatformSpecificHide(), then 112 // We should have closed any open menus in PlatformSpecificHide(), then
107 // subclasses' RunMenu() functions should have prevented opening any new ones 113 // subclasses' RunMenu() functions should have prevented opening any new ones
108 // once we became unowned. 114 // once we became unowned.
109 DCHECK(!menu_runner_.get()); 115 DCHECK(!menu_runner_.get());
110 } 116 }
111 117
112 views::Label* InfoBarView::CreateLabel(const base::string16& text) const { 118 views::Label* InfoBarView::CreateLabel(const base::string16& text) const {
113 views::Label* label = new views::Label(text, GetFontList()); 119 views::Label* label = new views::Label(text, GetFontList());
114 label->SizeToPreferredSize(); 120 label->SizeToPreferredSize();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // static 179 // static
174 void InfoBarView::AssignWidths(Labels* labels, int available_width) { 180 void InfoBarView::AssignWidths(Labels* labels, int available_width) {
175 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); 181 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
176 AssignWidthsSorted(labels, available_width); 182 AssignWidthsSorted(labels, available_width);
177 } 183 }
178 184
179 void InfoBarView::Layout() { 185 void InfoBarView::Layout() {
180 // Calculate the fill and stroke paths. We do this here, rather than in 186 // Calculate the fill and stroke paths. We do this here, rather than in
181 // PlatformSpecificRecalculateHeight(), because this is also reached when our 187 // PlatformSpecificRecalculateHeight(), because this is also reached when our
182 // width is changed, which affects both paths. 188 // width is changed, which affects both paths.
189 // TODO(estade): these paths aren't used for MD; remove when MD is default.
183 stroke_path_.rewind(); 190 stroke_path_.rewind();
184 fill_path_.rewind(); 191 fill_path_.rewind();
185 const infobars::InfoBarContainer::Delegate* delegate = container_delegate(); 192 const infobars::InfoBarContainer::Delegate* delegate = container_delegate();
186 if (delegate) { 193 if (delegate) {
187 static_cast<InfoBarBackground*>(background())->set_separator_color(
188 delegate->GetInfoBarSeparatorColor());
189 int arrow_x; 194 int arrow_x;
190 SkScalar arrow_fill_height = SkIntToScalar(std::max( 195 SkScalar arrow_fill_height = SkIntToScalar(std::max(
191 arrow_height() - InfoBarContainerDelegate::kSeparatorLineHeight, 0)); 196 arrow_height() - InfoBarContainerDelegate::kSeparatorLineHeight, 0));
192 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); 197 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width());
193 SkScalar separator_height = 198 SkScalar separator_height =
194 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight); 199 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight);
195 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { 200 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) {
196 // Skia pixel centers are at the half-values, so the arrow is horizontally 201 // Skia pixel centers are at the half-values, so the arrow is horizontally
197 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center 202 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center
198 // of the separator, while the fill path is a closed path that extends up 203 // of the separator, while the fill path is a closed path that extends up
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 330
326 int InfoBarView::EndX() const { 331 int InfoBarView::EndX() const {
327 return close_button_->x() - kBeforeCloseButtonSpacing; 332 return close_button_->x() - kBeforeCloseButtonSpacing;
328 } 333 }
329 334
330 int InfoBarView::OffsetY(views::View* view) const { 335 int InfoBarView::OffsetY(views::View* view) const {
331 return std::max((bar_target_height() - view->height()) / 2, 0) - 336 return std::max((bar_target_height() - view->height()) / 2, 0) -
332 (bar_target_height() - bar_height()); 337 (bar_target_height() - bar_height());
333 } 338 }
334 339
335 const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
336 const {
337 const infobars::InfoBarContainer* infobar_container = container();
338 return infobar_container ? infobar_container->delegate() : NULL;
339 }
340
341 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model, 340 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model,
342 views::MenuButton* button, 341 views::MenuButton* button,
343 views::MenuAnchorPosition anchor) { 342 views::MenuAnchorPosition anchor) {
344 DCHECK(owner()); // We'd better not open any menus while we're closing. 343 DCHECK(owner()); // We'd better not open any menus while we're closing.
345 gfx::Point screen_point; 344 gfx::Point screen_point;
346 views::View::ConvertPointToScreen(button, &screen_point); 345 views::View::ConvertPointToScreen(button, &screen_point);
347 menu_runner_.reset( 346 menu_runner_.reset(
348 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS)); 347 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS));
349 // Ignore the result since we don't need to handle a deleted menu specially. 348 // Ignore the result since we don't need to handle a deleted menu specially.
350 ignore_result(menu_runner_->RunMenuAt(GetWidget(), 349 ignore_result(menu_runner_->RunMenuAt(GetWidget(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 435 }
437 436
438 bool InfoBarView::DoesIntersectRect(const View* target, 437 bool InfoBarView::DoesIntersectRect(const View* target,
439 const gfx::Rect& rect) const { 438 const gfx::Rect& rect) const {
440 DCHECK_EQ(this, target); 439 DCHECK_EQ(this, target);
441 // Only events that intersect the portion below the arrow are interesting. 440 // Only events that intersect the portion below the arrow are interesting.
442 gfx::Rect non_arrow_bounds = GetLocalBounds(); 441 gfx::Rect non_arrow_bounds = GetLocalBounds();
443 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); 442 non_arrow_bounds.Inset(0, arrow_height(), 0, 0);
444 return rect.Intersects(non_arrow_bounds); 443 return rect.Intersects(non_arrow_bounds);
445 } 444 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698