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

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: move path calc 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
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 173
168 // static 174 // static
169 void InfoBarView::AssignWidths(Labels* labels, int available_width) { 175 void InfoBarView::AssignWidths(Labels* labels, int available_width) {
170 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); 176 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
171 AssignWidthsSorted(labels, available_width); 177 AssignWidthsSorted(labels, available_width);
172 } 178 }
173 179
174 void InfoBarView::Layout() { 180 void InfoBarView::Layout() {
175 // Calculate the fill and stroke paths. We do this here, rather than in 181 // Calculate the fill and stroke paths. We do this here, rather than in
176 // PlatformSpecificRecalculateHeight(), because this is also reached when our 182 // PlatformSpecificRecalculateHeight(), because this is also reached when our
177 // width is changed, which affects both paths. 183 // width is changed, which affects both paths.
Peter Kasting 2016/03/30 00:20:26 Nit: Might want removal TODO here also
Evan Stade 2016/04/02 02:21:42 Done.
178 stroke_path_.rewind(); 184 stroke_path_.rewind();
179 fill_path_.rewind(); 185 fill_path_.rewind();
180 const infobars::InfoBarContainer::Delegate* delegate = container_delegate(); 186 const infobars::InfoBarContainer::Delegate* delegate = container_delegate();
181 if (delegate) { 187 if (delegate) {
182 static_cast<InfoBarBackground*>(background())->set_separator_color(
183 delegate->GetInfoBarSeparatorColor());
184 int arrow_x; 188 int arrow_x;
185 SkScalar arrow_fill_height = SkIntToScalar(std::max( 189 SkScalar arrow_fill_height = SkIntToScalar(std::max(
186 arrow_height() - InfoBarContainerDelegate::kSeparatorLineHeight, 0)); 190 arrow_height() - InfoBarContainerDelegate::kSeparatorLineHeight, 0));
187 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); 191 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width());
188 SkScalar separator_height = 192 SkScalar separator_height =
189 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight); 193 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight);
190 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { 194 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) {
191 // Skia pixel centers are at the half-values, so the arrow is horizontally 195 // Skia pixel centers are at the half-values, so the arrow is horizontally
192 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center 196 // centered at |arrow_x| + 0.5. Vertically, the stroke path is the center
193 // of the separator, while the fill path is a closed path that extends up 197 // 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
320 324
321 int InfoBarView::EndX() const { 325 int InfoBarView::EndX() const {
322 return close_button_->x() - kBeforeCloseButtonSpacing; 326 return close_button_->x() - kBeforeCloseButtonSpacing;
323 } 327 }
324 328
325 int InfoBarView::OffsetY(views::View* view) const { 329 int InfoBarView::OffsetY(views::View* view) const {
326 return std::max((bar_target_height() - view->height()) / 2, 0) - 330 return std::max((bar_target_height() - view->height()) / 2, 0) -
327 (bar_target_height() - bar_height()); 331 (bar_target_height() - bar_height());
328 } 332 }
329 333
330 const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
331 const {
332 const infobars::InfoBarContainer* infobar_container = container();
333 return infobar_container ? infobar_container->delegate() : NULL;
334 }
335
336 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model, 334 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model,
337 views::MenuButton* button, 335 views::MenuButton* button,
338 views::MenuAnchorPosition anchor) { 336 views::MenuAnchorPosition anchor) {
339 DCHECK(owner()); // We'd better not open any menus while we're closing. 337 DCHECK(owner()); // We'd better not open any menus while we're closing.
340 gfx::Point screen_point; 338 gfx::Point screen_point;
341 views::View::ConvertPointToScreen(button, &screen_point); 339 views::View::ConvertPointToScreen(button, &screen_point);
342 menu_runner_.reset( 340 menu_runner_.reset(
343 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS)); 341 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS));
344 // Ignore the result since we don't need to handle a deleted menu specially. 342 // Ignore the result since we don't need to handle a deleted menu specially.
345 ignore_result(menu_runner_->RunMenuAt(GetWidget(), 343 ignore_result(menu_runner_->RunMenuAt(GetWidget(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 429 }
432 430
433 bool InfoBarView::DoesIntersectRect(const View* target, 431 bool InfoBarView::DoesIntersectRect(const View* target,
434 const gfx::Rect& rect) const { 432 const gfx::Rect& rect) const {
435 DCHECK_EQ(this, target); 433 DCHECK_EQ(this, target);
436 // Only events that intersect the portion below the arrow are interesting. 434 // Only events that intersect the portion below the arrow are interesting.
437 gfx::Rect non_arrow_bounds = GetLocalBounds(); 435 gfx::Rect non_arrow_bounds = GetLocalBounds();
438 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); 436 non_arrow_bounds.Inset(0, arrow_height(), 0, 0);
439 return rect.Intersects(non_arrow_bounds); 437 return rect.Intersects(non_arrow_bounds);
440 } 438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698