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

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: fix comment typo Created 4 years, 9 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); 187 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width());
188 SkScalar separator_height = 188 SkScalar separator_height =
189 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight); 189 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight);
190 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { 190 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) {
191 // Skia pixel centers are at the half-values, so the arrow is horizontally 191 // 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 192 // 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 193 // of the separator, while the fill path is a closed path that extends up
194 // through the entire height of the separator and down to the bottom of 194 // through the entire height of the separator and down to the bottom of
195 // the arrow where it joins the bar. 195 // the arrow where it joins the bar.
196 stroke_path_.moveTo( 196 stroke_path_.moveTo(
197 SkIntToScalar(arrow_x) + SK_ScalarHalf - arrow_fill_half_width, 197 SkIntToScalar(arrow_x) + SK_ScalarHalf - arrow_fill_half_width,
Peter Kasting 2016/03/25 05:07:46 This 0.5 adjustment is still going to be incorrect
Evan Stade 2016/03/28 21:44:36 Yes, at 2x the point is 2px wide, but I don't thin
Peter Kasting 2016/03/29 01:04:00 At odd integral scale factors, the tip will look c
198 SkIntToScalar(arrow_height()) - (separator_height * SK_ScalarHalf)); 198 SkIntToScalar(arrow_height()) - (separator_height * SK_ScalarHalf));
199 stroke_path_.rLineTo(arrow_fill_half_width, -arrow_fill_height); 199 stroke_path_.rLineTo(arrow_fill_half_width, -arrow_fill_height);
200 stroke_path_.rLineTo(arrow_fill_half_width, arrow_fill_height); 200 stroke_path_.rLineTo(arrow_fill_half_width, arrow_fill_height);
201 201
202 fill_path_ = stroke_path_; 202 fill_path_ = stroke_path_;
203 // Move the top of the fill path up to the top of the separator and then
204 // extend it down all the way through.
205 fill_path_.offset(0, -separator_height * SK_ScalarHalf);
206 // This 0.01 hack prevents the fill from filling more pixels on the right 203 // This 0.01 hack prevents the fill from filling more pixels on the right
207 // edge of the arrow than on the left. 204 // edge of the arrow than on the left.
208 const SkScalar epsilon = 0.01f; 205 const SkScalar epsilon = 0.01f;
209 fill_path_.rLineTo(-epsilon, 0); 206 fill_path_.rLineTo(-epsilon, 0);
210 fill_path_.rLineTo(0, separator_height); 207 fill_path_.rLineTo(0, separator_height);
211 fill_path_.rLineTo(epsilon - (arrow_fill_half_width * 2), 0); 208 fill_path_.rLineTo(epsilon - (arrow_fill_half_width * 2), 0);
212 fill_path_.close(); 209 fill_path_.close();
213 } 210 }
214 } 211 }
215 if (bar_height()) { 212 if (bar_height()) {
216 fill_path_.addRect( 213 fill_path_.addRect(0.0, SkIntToScalar(arrow_height()),
217 0.0, SkIntToScalar(arrow_height()), SkIntToScalar(width()), 214 SkIntToScalar(width()), SkIntToScalar(height()));
218 SkIntToScalar(
219 height() - InfoBarContainerDelegate::kSeparatorLineHeight));
220 } 215 }
221 216
222 child_container_->SetBounds( 217 child_container_->SetBounds(
223 0, arrow_height(), width(), 218 0, arrow_height(), width(),
224 bar_height() - InfoBarContainerDelegate::kSeparatorLineHeight); 219 bar_height() - InfoBarContainerDelegate::kSeparatorLineHeight);
225 // |child_container_| should be the only child. 220 // |child_container_| should be the only child.
226 DCHECK_EQ(1, child_count()); 221 DCHECK_EQ(1, child_count());
227 222
228 // Even though other views are technically grandchildren, we'll lay them out 223 // Even though other views are technically grandchildren, we'll lay them out
229 // here on behalf of |child_container_|. 224 // here on behalf of |child_container_|.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 426 }
432 427
433 bool InfoBarView::DoesIntersectRect(const View* target, 428 bool InfoBarView::DoesIntersectRect(const View* target,
434 const gfx::Rect& rect) const { 429 const gfx::Rect& rect) const {
435 DCHECK_EQ(this, target); 430 DCHECK_EQ(this, target);
436 // Only events that intersect the portion below the arrow are interesting. 431 // Only events that intersect the portion below the arrow are interesting.
437 gfx::Rect non_arrow_bounds = GetLocalBounds(); 432 gfx::Rect non_arrow_bounds = GetLocalBounds();
438 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); 433 non_arrow_bounds.Inset(0, arrow_height(), 0, 0);
439 return rect.Intersects(non_arrow_bounds); 434 return rect.Intersects(non_arrow_bounds);
440 } 435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698