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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 1534303002: CustomButton cleanup: make protected members private, create accessors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert a change Created 5 years 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/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // extended vertically to y = 0. The caller uses this for Fitts' Law purposes 301 // extended vertically to y = 0. The caller uses this for Fitts' Law purposes
302 // in maximized/fullscreen mode. 302 // in maximized/fullscreen mode.
303 void GetBorderPath(float button_y, 303 void GetBorderPath(float button_y,
304 float scale, 304 float scale,
305 bool extend_to_top, 305 bool extend_to_top,
306 SkPath* path) const; 306 SkPath* path) const;
307 307
308 // Paints the fill region of the button into |canvas|, according to the 308 // Paints the fill region of the button into |canvas|, according to the
309 // supplied values from GetImage() and the given |fill| path. 309 // supplied values from GetImage() and the given |fill| path.
310 void PaintFill(bool pressed, 310 void PaintFill(bool pressed,
311 double hover_value,
312 float scale, 311 float scale,
313 const SkPath& fill, 312 const SkPath& fill,
314 gfx::Canvas* canvas) const; 313 gfx::Canvas* canvas) const;
315 314
316 // Tab strip that contains this button. 315 // Tab strip that contains this button.
317 TabStrip* tab_strip_; 316 TabStrip* tab_strip_;
318 317
319 // The offset used to paint the background image. 318 // The offset used to paint the background image.
320 gfx::Point background_offset_; 319 gfx::Point background_offset_;
321 320
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // start consuming gestures. 364 // start consuming gestures.
366 views::ImageButton::OnGestureEvent(event); 365 views::ImageButton::OnGestureEvent(event);
367 event->SetHandled(); 366 event->SetHandled();
368 } 367 }
369 368
370 void NewTabButton::OnPaint(gfx::Canvas* canvas) { 369 void NewTabButton::OnPaint(gfx::Canvas* canvas) {
371 gfx::ScopedCanvas scoped_canvas(canvas); 370 gfx::ScopedCanvas scoped_canvas(canvas);
372 canvas->Translate(gfx::Vector2d(0, height() - kNewTabButtonHeight)); 371 canvas->Translate(gfx::Vector2d(0, height() - kNewTabButtonHeight));
373 372
374 const bool pressed = state() == views::CustomButton::STATE_PRESSED; 373 const bool pressed = state() == views::CustomButton::STATE_PRESSED;
375 double hover_value =
376 (state() == views::CustomButton::STATE_HOVERED) ? 1 : 0;
377 if (hover_animation_->is_animating())
378 hover_value = hover_animation_->GetCurrentValue();
Peter Kasting 2015/12/19 01:22:27 I _think_ your changes to always trust the animati
Evan Stade 2015/12/21 20:19:28 I've tried every combination of hovering, clicking
379 const float scale = canvas->image_scale(); 374 const float scale = canvas->image_scale();
380 375
381 SkPath fill; 376 SkPath fill;
382 if (ui::MaterialDesignController::IsModeMaterial()) { 377 if (ui::MaterialDesignController::IsModeMaterial()) {
383 // Fill. 378 // Fill.
384 fill.moveTo(9.75 * scale, 16 * scale); 379 fill.moveTo(9.75 * scale, 16 * scale);
385 fill.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale, -2 * scale, 380 fill.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale, -2 * scale,
386 -1.5 * scale); 381 -1.5 * scale);
387 fill.rLineTo(-5.75 * scale, -12.5 * scale); 382 fill.rLineTo(-5.75 * scale, -12.5 * scale);
388 fill.rCubicTo(0, -0.5 * scale, 0.25 * scale, -scale, scale, -scale); 383 fill.rCubicTo(0, -0.5 * scale, 0.25 * scale, -scale, scale, -scale);
389 fill.rLineTo(23.25 * scale, 0); 384 fill.rLineTo(23.25 * scale, 0);
390 fill.rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale, 385 fill.rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale,
391 1.5 * scale); 386 1.5 * scale);
392 fill.rLineTo(5.75 * scale, 12.5 * scale); 387 fill.rLineTo(5.75 * scale, 12.5 * scale);
393 fill.rCubicTo(0, 0.5 * scale, -0.25 * scale, scale, -scale, scale); 388 fill.rCubicTo(0, 0.5 * scale, -0.25 * scale, scale, -scale, scale);
394 fill.close(); 389 fill.close();
395 PaintFill(pressed, hover_value, scale, fill, canvas); 390 PaintFill(pressed, scale, fill, canvas);
396 391
397 // Stroke. 392 // Stroke.
398 gfx::ScopedCanvas scoped_canvas(canvas); 393 gfx::ScopedCanvas scoped_canvas(canvas);
399 canvas->UndoDeviceScaleFactor(); 394 canvas->UndoDeviceScaleFactor();
400 SkPath stroke; 395 SkPath stroke;
401 GetBorderPath(0, scale, false, &stroke); 396 GetBorderPath(0, scale, false, &stroke);
402 // We want to draw a drop shadow either inside or outside the stroke, 397 // We want to draw a drop shadow either inside or outside the stroke,
403 // depending on whether we're pressed; so, either clip out what's outside 398 // depending on whether we're pressed; so, either clip out what's outside
404 // the stroke, or clip out the fill inside it. 399 // the stroke, or clip out the fill inside it.
405 if (pressed) 400 if (pressed)
(...skipping 10 matching lines...) Expand all
416 paint.setColor(SkColorSetA(SK_ColorBLACK, pressed ? 0x38 : 0x27)); 411 paint.setColor(SkColorSetA(SK_ColorBLACK, pressed ? 0x38 : 0x27));
417 canvas->DrawPath(stroke, paint); 412 canvas->DrawPath(stroke, paint);
418 } else { 413 } else {
419 // Fill. 414 // Fill.
420 gfx::ImageSkia* mask = 415 gfx::ImageSkia* mask =
421 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); 416 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
422 // The canvas and mask have to use the same scale factor. 417 // The canvas and mask have to use the same scale factor.
423 const float fill_canvas_scale = mask->HasRepresentation(scale) ? 418 const float fill_canvas_scale = mask->HasRepresentation(scale) ?
424 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P); 419 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
425 gfx::Canvas fill_canvas(GetNewTabButtonSize(), fill_canvas_scale, false); 420 gfx::Canvas fill_canvas(GetNewTabButtonSize(), fill_canvas_scale, false);
426 PaintFill(pressed, hover_value, fill_canvas_scale, fill, &fill_canvas); 421 PaintFill(pressed, fill_canvas_scale, fill, &fill_canvas);
427 gfx::ImageSkia image(fill_canvas.ExtractImageRep()); 422 gfx::ImageSkia image(fill_canvas.ExtractImageRep());
428 canvas->DrawImageInt( 423 canvas->DrawImageInt(
429 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0); 424 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0);
430 425
431 // Stroke. Draw the button border with a slight alpha. 426 // Stroke. Draw the button border with a slight alpha.
432 static const SkAlpha kGlassFrameOverlayAlpha = 178; 427 static const SkAlpha kGlassFrameOverlayAlpha = 178;
433 static const SkAlpha kOpaqueFrameOverlayAlpha = 230; 428 static const SkAlpha kOpaqueFrameOverlayAlpha = 230;
434 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? 429 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ?
435 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; 430 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha;
436 const int overlay_id = pressed ? IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; 431 const int overlay_id = pressed ? IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 path->rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale, 499 path->rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale,
505 1.5 * scale); 500 1.5 * scale);
506 path->rLineTo(5.75 * scale, 12.5 * scale); 501 path->rLineTo(5.75 * scale, 12.5 * scale);
507 path->rCubicTo(0.5 * scale, 1.125 * scale, -0.5 * scale, scale + 2, -scale, 502 path->rCubicTo(0.5 * scale, 1.125 * scale, -0.5 * scale, scale + 2, -scale,
508 scale + 2); 503 scale + 2);
509 } 504 }
510 path->close(); 505 path->close();
511 } 506 }
512 507
513 void NewTabButton::PaintFill(bool pressed, 508 void NewTabButton::PaintFill(bool pressed,
514 double hover_value,
515 float scale, 509 float scale,
516 const SkPath& fill, 510 const SkPath& fill,
517 gfx::Canvas* canvas) const { 511 gfx::Canvas* canvas) const {
518 bool custom_image; 512 bool custom_image;
519 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image); 513 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image);
520 514
521 gfx::ScopedCanvas scoped_canvas(canvas); 515 gfx::ScopedCanvas scoped_canvas(canvas);
522 516
523 const bool md = ui::MaterialDesignController::IsModeMaterial(); 517 const bool md = ui::MaterialDesignController::IsModeMaterial();
524 if (md) { 518 if (md) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (alpha != 255 && !md) { 578 if (alpha != 255 && !md) {
585 SkPaint paint; 579 SkPaint paint;
586 paint.setAlpha(alpha); 580 paint.setAlpha(alpha);
587 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 581 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
588 paint.setStyle(SkPaint::kFill_Style); 582 paint.setStyle(SkPaint::kFill_Style);
589 canvas->DrawRect(gfx::Rect(size), paint); 583 canvas->DrawRect(gfx::Rect(size), paint);
590 } 584 }
591 } 585 }
592 586
593 // White highlight on hover. 587 // White highlight on hover.
594 if (hover_value) { 588 if (hover_animation().GetCurrentValue()) {
Peter Kasting 2015/12/19 01:22:27 Nit: Store this in a temp to avoid multiple calls
Evan Stade 2015/12/21 20:19:28 question: you authored this code recently. Why doe
Peter Kasting 2015/12/21 20:34:18 Using LinearIntValueBetween() matched the previous
595 const int alpha = 589 const int alpha = gfx::Tween::LinearIntValueBetween(
596 gfx::Tween::LinearIntValueBetween(hover_value, 0x00, md ? 0x4D : 0x40); 590 hover_animation().GetCurrentValue(), 0x00, md ? 0x4D : 0x40);
597 canvas->FillRect(GetLocalBounds(), 591 canvas->FillRect(GetLocalBounds(),
598 SkColorSetA(SK_ColorWHITE, static_cast<SkAlpha>(alpha))); 592 SkColorSetA(SK_ColorWHITE, static_cast<SkAlpha>(alpha)));
599 } 593 }
600 594
601 // For MD, most states' opacities are adjusted using an opacity recorder in 595 // For MD, most states' opacities are adjusted using an opacity recorder in
602 // TabStrip::PaintChildren(), but the pressed state is excluded there and 596 // TabStrip::PaintChildren(), but the pressed state is excluded there and
603 // instead rendered using a dark overlay here. This produces a different 597 // instead rendered using a dark overlay here. This produces a different
604 // effect than for non-MD, and avoiding the use of the opacity recorder keeps 598 // effect than for non-MD, and avoiding the use of the opacity recorder keeps
605 // the stroke more visible in this state. 599 // the stroke more visible in this state.
606 if (md && pressed) 600 if (md && pressed)
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after
2852 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2846 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2853 if (view) 2847 if (view)
2854 return view; 2848 return view;
2855 } 2849 }
2856 Tab* tab = FindTabForEvent(point); 2850 Tab* tab = FindTabForEvent(point);
2857 if (tab) 2851 if (tab)
2858 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2852 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2859 } 2853 }
2860 return this; 2854 return this;
2861 } 2855 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/media_indicator_button.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698