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

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: dont move declaration randomly Created 4 years, 11 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/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // extended vertically to y = 0. The caller uses this for Fitts' Law purposes 306 // extended vertically to y = 0. The caller uses this for Fitts' Law purposes
307 // in maximized/fullscreen mode. 307 // in maximized/fullscreen mode.
308 void GetBorderPath(float button_y, 308 void GetBorderPath(float button_y,
309 float scale, 309 float scale,
310 bool extend_to_top, 310 bool extend_to_top,
311 SkPath* path) const; 311 SkPath* path) const;
312 312
313 // Paints the fill region of the button into |canvas|, according to the 313 // Paints the fill region of the button into |canvas|, according to the
314 // supplied values from GetImage() and the given |fill| path. 314 // supplied values from GetImage() and the given |fill| path.
315 void PaintFill(bool pressed, 315 void PaintFill(bool pressed,
316 double hover_value,
317 float scale, 316 float scale,
318 const SkPath& fill, 317 const SkPath& fill,
319 gfx::Canvas* canvas) const; 318 gfx::Canvas* canvas) const;
320 319
321 // Tab strip that contains this button. 320 // Tab strip that contains this button.
322 TabStrip* tab_strip_; 321 TabStrip* tab_strip_;
323 322
324 // The offset used to paint the background image. 323 // The offset used to paint the background image.
325 gfx::Point background_offset_; 324 gfx::Point background_offset_;
326 325
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 views::ImageButton::OnGestureEvent(event); 370 views::ImageButton::OnGestureEvent(event);
372 event->SetHandled(); 371 event->SetHandled();
373 } 372 }
374 373
375 void NewTabButton::OnPaint(gfx::Canvas* canvas) { 374 void NewTabButton::OnPaint(gfx::Canvas* canvas) {
376 gfx::ScopedCanvas scoped_canvas(canvas); 375 gfx::ScopedCanvas scoped_canvas(canvas);
377 const int visible_height = GetLayoutSize(NEW_TAB_BUTTON).height(); 376 const int visible_height = GetLayoutSize(NEW_TAB_BUTTON).height();
378 canvas->Translate(gfx::Vector2d(0, height() - visible_height)); 377 canvas->Translate(gfx::Vector2d(0, height() - visible_height));
379 378
380 const bool pressed = state() == views::CustomButton::STATE_PRESSED; 379 const bool pressed = state() == views::CustomButton::STATE_PRESSED;
381 double hover_value =
382 (state() == views::CustomButton::STATE_HOVERED) ? 1 : 0;
383 if (hover_animation_->is_animating())
384 hover_value = hover_animation_->GetCurrentValue();
385 const float scale = canvas->image_scale(); 380 const float scale = canvas->image_scale();
386 381
387 SkPath fill; 382 SkPath fill;
388 if (ui::MaterialDesignController::IsModeMaterial()) { 383 if (ui::MaterialDesignController::IsModeMaterial()) {
389 // Fill. 384 // Fill.
390 const float fill_bottom = (visible_height - 2) * scale; 385 const float fill_bottom = (visible_height - 2) * scale;
391 const float diag_height = fill_bottom - 3.5 * scale; 386 const float diag_height = fill_bottom - 3.5 * scale;
392 const float diag_width = diag_height * Tab::GetInverseDiagonalSlope(); 387 const float diag_width = diag_height * Tab::GetInverseDiagonalSlope();
393 fill.moveTo(diag_width + 4 * scale, fill_bottom); 388 fill.moveTo(diag_width + 4 * scale, fill_bottom);
394 fill.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale, -2 * scale, 389 fill.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale, -2 * scale,
395 -1.5 * scale); 390 -1.5 * scale);
396 fill.rLineTo(-diag_width, -diag_height); 391 fill.rLineTo(-diag_width, -diag_height);
397 fill.rCubicTo(0, -0.5 * scale, 0.25 * scale, -scale, scale, -scale); 392 fill.rCubicTo(0, -0.5 * scale, 0.25 * scale, -scale, scale, -scale);
398 fill.lineTo((width() - 4) * scale - diag_width, scale); 393 fill.lineTo((width() - 4) * scale - diag_width, scale);
399 fill.rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale, 394 fill.rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale,
400 1.5 * scale); 395 1.5 * scale);
401 fill.rLineTo(diag_width, diag_height); 396 fill.rLineTo(diag_width, diag_height);
402 fill.rCubicTo(0, 0.5 * scale, -0.25 * scale, scale, -scale, scale); 397 fill.rCubicTo(0, 0.5 * scale, -0.25 * scale, scale, -scale, scale);
403 fill.close(); 398 fill.close();
404 PaintFill(pressed, hover_value, scale, fill, canvas); 399 PaintFill(pressed, scale, fill, canvas);
405 400
406 // Stroke. 401 // Stroke.
407 gfx::ScopedCanvas scoped_canvas(canvas); 402 gfx::ScopedCanvas scoped_canvas(canvas);
408 canvas->UndoDeviceScaleFactor(); 403 canvas->UndoDeviceScaleFactor();
409 SkPath stroke; 404 SkPath stroke;
410 GetBorderPath(0, scale, false, &stroke); 405 GetBorderPath(0, scale, false, &stroke);
411 // We want to draw a drop shadow either inside or outside the stroke, 406 // We want to draw a drop shadow either inside or outside the stroke,
412 // depending on whether we're pressed; so, either clip out what's outside 407 // depending on whether we're pressed; so, either clip out what's outside
413 // the stroke, or clip out the fill inside it. 408 // the stroke, or clip out the fill inside it.
414 if (pressed) 409 if (pressed)
(...skipping 11 matching lines...) Expand all
426 canvas->DrawPath(stroke, paint); 421 canvas->DrawPath(stroke, paint);
427 } else { 422 } else {
428 // Fill. 423 // Fill.
429 gfx::ImageSkia* mask = 424 gfx::ImageSkia* mask =
430 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); 425 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
431 // The canvas and mask have to use the same scale factor. 426 // The canvas and mask have to use the same scale factor.
432 const float fill_canvas_scale = mask->HasRepresentation(scale) ? 427 const float fill_canvas_scale = mask->HasRepresentation(scale) ?
433 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P); 428 scale : ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
434 gfx::Canvas fill_canvas(GetLayoutSize(NEW_TAB_BUTTON), fill_canvas_scale, 429 gfx::Canvas fill_canvas(GetLayoutSize(NEW_TAB_BUTTON), fill_canvas_scale,
435 false); 430 false);
436 PaintFill(pressed, hover_value, fill_canvas_scale, fill, &fill_canvas); 431 PaintFill(pressed, fill_canvas_scale, fill, &fill_canvas);
437 gfx::ImageSkia image(fill_canvas.ExtractImageRep()); 432 gfx::ImageSkia image(fill_canvas.ExtractImageRep());
438 canvas->DrawImageInt( 433 canvas->DrawImageInt(
439 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0); 434 gfx::ImageSkiaOperations::CreateMaskedImage(image, *mask), 0, 0);
440 435
441 // Stroke. Draw the button border with a slight alpha. 436 // Stroke. Draw the button border with a slight alpha.
442 static const SkAlpha kGlassFrameOverlayAlpha = 178; 437 static const SkAlpha kGlassFrameOverlayAlpha = 178;
443 static const SkAlpha kOpaqueFrameOverlayAlpha = 230; 438 static const SkAlpha kOpaqueFrameOverlayAlpha = 230;
444 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ? 439 const SkAlpha alpha = GetWidget()->ShouldWindowContentsBeTransparent() ?
445 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; 440 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha;
446 const int overlay_id = pressed ? IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; 441 const int overlay_id = pressed ? IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 path->rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale, 515 path->rCubicTo(0.75 * scale, 0, 1.625 * scale, 0.5 * scale, 2 * scale,
521 1.5 * scale); 516 1.5 * scale);
522 path->rLineTo(diag_width, diag_height); 517 path->rLineTo(diag_width, diag_height);
523 path->rCubicTo(0.5 * scale, 1.125 * scale, -0.5 * scale, scale + 2, -scale, 518 path->rCubicTo(0.5 * scale, 1.125 * scale, -0.5 * scale, scale + 2, -scale,
524 scale + 2); 519 scale + 2);
525 } 520 }
526 path->close(); 521 path->close();
527 } 522 }
528 523
529 void NewTabButton::PaintFill(bool pressed, 524 void NewTabButton::PaintFill(bool pressed,
530 double hover_value,
531 float scale, 525 float scale,
532 const SkPath& fill, 526 const SkPath& fill,
533 gfx::Canvas* canvas) const { 527 gfx::Canvas* canvas) const {
534 bool custom_image; 528 bool custom_image;
535 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image); 529 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image);
536 530
537 gfx::ScopedCanvas scoped_canvas(canvas); 531 gfx::ScopedCanvas scoped_canvas(canvas);
538 532
539 const bool md = ui::MaterialDesignController::IsModeMaterial(); 533 const bool md = ui::MaterialDesignController::IsModeMaterial();
540 if (md) { 534 if (md) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 if (alpha != 255 && !md) { 593 if (alpha != 255 && !md) {
600 SkPaint paint; 594 SkPaint paint;
601 paint.setAlpha(alpha); 595 paint.setAlpha(alpha);
602 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 596 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
603 paint.setStyle(SkPaint::kFill_Style); 597 paint.setStyle(SkPaint::kFill_Style);
604 canvas->DrawRect(gfx::Rect(size), paint); 598 canvas->DrawRect(gfx::Rect(size), paint);
605 } 599 }
606 } 600 }
607 601
608 // White highlight on hover. 602 // White highlight on hover.
609 if (hover_value) { 603 const SkAlpha alpha = static_cast<SkAlpha>(
610 const int alpha = 604 hover_animation().CurrentValueBetween(0x00, md ? 0x4D : 0x40));
611 gfx::Tween::LinearIntValueBetween(hover_value, 0x00, md ? 0x4D : 0x40); 605 if (alpha != SK_AlphaTRANSPARENT)
612 canvas->FillRect(GetLocalBounds(), 606 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorWHITE, alpha));
613 SkColorSetA(SK_ColorWHITE, static_cast<SkAlpha>(alpha)));
614 }
615 607
616 // For MD, most states' opacities are adjusted using an opacity recorder in 608 // For MD, most states' opacities are adjusted using an opacity recorder in
617 // TabStrip::PaintChildren(), but the pressed state is excluded there and 609 // TabStrip::PaintChildren(), but the pressed state is excluded there and
618 // instead rendered using a dark overlay here. This produces a different 610 // instead rendered using a dark overlay here. This produces a different
619 // effect than for non-MD, and avoiding the use of the opacity recorder keeps 611 // effect than for non-MD, and avoiding the use of the opacity recorder keeps
620 // the stroke more visible in this state. 612 // the stroke more visible in this state.
621 if (md && pressed) 613 if (md && pressed)
622 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, 0x14)); 614 canvas->FillRect(GetLocalBounds(), SkColorSetA(SK_ColorBLACK, 0x14));
623 } 615 }
624 616
(...skipping 2239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2864 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2856 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2865 if (view) 2857 if (view)
2866 return view; 2858 return view;
2867 } 2859 }
2868 Tab* tab = FindTabForEvent(point); 2860 Tab* tab = FindTabForEvent(point);
2869 if (tab) 2861 if (tab)
2870 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2862 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2871 } 2863 }
2872 return this; 2864 return this;
2873 } 2865 }
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