OLD | NEW |
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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
33 #include "grit/theme_resources_standard.h" | 33 #include "grit/theme_resources_standard.h" |
34 #include "ui/base/accessibility/accessible_view_state.h" | 34 #include "ui/base/accessibility/accessible_view_state.h" |
35 #include "ui/base/animation/animation_container.h" | 35 #include "ui/base/animation/animation_container.h" |
36 #include "ui/base/animation/throb_animation.h" | 36 #include "ui/base/animation/throb_animation.h" |
37 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/layout.h" | 39 #include "ui/base/layout.h" |
40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 42 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/image/image_skia_operations.h" |
42 #include "ui/gfx/path.h" | 44 #include "ui/gfx/path.h" |
43 #include "ui/gfx/screen.h" | 45 #include "ui/gfx/screen.h" |
44 #include "ui/gfx/size.h" | 46 #include "ui/gfx/size.h" |
45 #include "ui/gfx/skbitmap_operations.h" | |
46 #include "ui/views/controls/image_view.h" | 47 #include "ui/views/controls/image_view.h" |
47 #include "ui/views/mouse_watcher_view_host.h" | 48 #include "ui/views/mouse_watcher_view_host.h" |
48 #include "ui/views/view_model_utils.h" | 49 #include "ui/views/view_model_utils.h" |
49 #include "ui/views/widget/default_theme_provider.h" | 50 #include "ui/views/widget/default_theme_provider.h" |
50 #include "ui/views/widget/root_view.h" | 51 #include "ui/views/widget/root_view.h" |
51 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
52 #include "ui/views/window/non_client_view.h" | 53 #include "ui/views/window/non_client_view.h" |
53 | 54 |
54 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
55 #include "base/win/metro.h" | 56 #include "base/win/metro.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; | 296 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; |
296 #if defined(OS_WIN) && !defined(USE_AURA) | 297 #if defined(OS_WIN) && !defined(USE_AURA) |
297 void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 298 void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
298 #endif | 299 #endif |
299 virtual ui::GestureStatus OnGestureEvent( | 300 virtual ui::GestureStatus OnGestureEvent( |
300 const views::GestureEvent& event) OVERRIDE; | 301 const views::GestureEvent& event) OVERRIDE; |
301 void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 302 void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
302 | 303 |
303 private: | 304 private: |
304 bool ShouldUseNativeFrame() const; | 305 bool ShouldUseNativeFrame() const; |
305 SkBitmap GetBackgroundBitmap(views::CustomButton::ButtonState state) const; | 306 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, |
306 SkBitmap GetBitmapForState(views::CustomButton::ButtonState state) const; | 307 ui::ScaleFactor scale_factor) const; |
307 SkBitmap GetBitmap() const; | 308 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, |
| 309 ui::ScaleFactor scale_factor) const; |
| 310 gfx::ImageSkia GetImage(ui::ScaleFactor scale_factor) const; |
308 | 311 |
309 // Tab strip that contains this button. | 312 // Tab strip that contains this button. |
310 TabStrip* tab_strip_; | 313 TabStrip* tab_strip_; |
311 | 314 |
312 // The offset used to paint the background image. | 315 // The offset used to paint the background image. |
313 gfx::Point background_offset_; | 316 gfx::Point background_offset_; |
314 | 317 |
315 DISALLOW_COPY_AND_ASSIGN(NewTabButton); | 318 DISALLOW_COPY_AND_ASSIGN(NewTabButton); |
316 }; | 319 }; |
317 | 320 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 | 368 |
366 ui::GestureStatus NewTabButton::OnGestureEvent( | 369 ui::GestureStatus NewTabButton::OnGestureEvent( |
367 const views::GestureEvent& event) { | 370 const views::GestureEvent& event) { |
368 // Consume all gesture events here so that the parent (BaseTab) does not | 371 // Consume all gesture events here so that the parent (BaseTab) does not |
369 // start consuming gestures. | 372 // start consuming gestures. |
370 views::ImageButton::OnGestureEvent(event); | 373 views::ImageButton::OnGestureEvent(event); |
371 return ui::GESTURE_STATUS_CONSUMED; | 374 return ui::GESTURE_STATUS_CONSUMED; |
372 } | 375 } |
373 | 376 |
374 void NewTabButton::OnPaint(gfx::Canvas* canvas) { | 377 void NewTabButton::OnPaint(gfx::Canvas* canvas) { |
375 SkBitmap image = GetBitmap(); | 378 gfx::ImageSkia image = GetImage(canvas->scale_factor()); |
376 canvas->DrawImageInt(image, 0, height() - image.height()); | 379 canvas->DrawImageInt(image, 0, height() - image.height()); |
377 } | 380 } |
378 | 381 |
379 bool NewTabButton::ShouldUseNativeFrame() const { | 382 bool NewTabButton::ShouldUseNativeFrame() const { |
380 return GetWidget() && | 383 return GetWidget() && |
381 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); | 384 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); |
382 } | 385 } |
383 | 386 |
384 SkBitmap NewTabButton::GetBackgroundBitmap( | 387 gfx::ImageSkia NewTabButton::GetBackgroundImage( |
385 views::CustomButton::ButtonState state) const { | 388 views::CustomButton::ButtonState state, |
| 389 ui::ScaleFactor scale_factor) const { |
386 int background_id = 0; | 390 int background_id = 0; |
387 if (ShouldUseNativeFrame()) { | 391 if (ShouldUseNativeFrame()) { |
388 background_id = IDR_THEME_TAB_BACKGROUND_V; | 392 background_id = IDR_THEME_TAB_BACKGROUND_V; |
389 } else { | 393 } else { |
390 background_id = tab_strip_->controller()->IsIncognito() ? | 394 background_id = tab_strip_->controller()->IsIncognito() ? |
391 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; | 395 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; |
392 } | 396 } |
393 | 397 |
394 int alpha = 0; | 398 int alpha = 0; |
395 switch (state) { | 399 switch (state) { |
396 case views::CustomButton::BS_NORMAL: | 400 case views::CustomButton::BS_NORMAL: |
397 case views::CustomButton::BS_HOT: | 401 case views::CustomButton::BS_HOT: |
398 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; | 402 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; |
399 break; | 403 break; |
400 case views::CustomButton::BS_PUSHED: | 404 case views::CustomButton::BS_PUSHED: |
401 alpha = 145; | 405 alpha = 145; |
402 break; | 406 break; |
403 default: | 407 default: |
404 NOTREACHED(); | 408 NOTREACHED(); |
405 break; | 409 break; |
406 } | 410 } |
407 | 411 |
408 gfx::ImageSkia* mask = | 412 gfx::ImageSkia* mask = |
409 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); | 413 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); |
410 int height = mask->height(); | 414 int height = mask->height(); |
411 int width = mask->width(); | 415 int width = mask->width(); |
412 gfx::Canvas canvas(gfx::Size(width, height), false); | 416 gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false); |
413 | 417 |
414 // For custom images the background starts at the top of the tab strip. | 418 // For custom images the background starts at the top of the tab strip. |
415 // Otherwise the background starts at the top of the frame. | 419 // Otherwise the background starts at the top of the frame. |
416 gfx::ImageSkia* background = | 420 gfx::ImageSkia* background = |
417 GetThemeProvider()->GetImageSkiaNamed(background_id); | 421 GetThemeProvider()->GetImageSkiaNamed(background_id); |
418 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? | 422 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? |
419 0 : background_offset_.y(); | 423 0 : background_offset_.y(); |
420 canvas.TileImageInt(*background, GetMirroredX() + background_offset_.x(), | 424 canvas.TileImageInt(*background, GetMirroredX() + background_offset_.x(), |
421 newtab_button_v_offset() + offset_y, 0, 0, width, height); | 425 newtab_button_v_offset() + offset_y, 0, 0, width, height); |
422 | 426 |
423 if (alpha != 255) { | 427 if (alpha != 255) { |
424 SkPaint paint; | 428 SkPaint paint; |
425 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); | 429 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
426 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 430 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
427 paint.setStyle(SkPaint::kFill_Style); | 431 paint.setStyle(SkPaint::kFill_Style); |
428 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); | 432 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); |
429 } | 433 } |
430 | 434 |
431 // White highlight on hover. | 435 // White highlight on hover. |
432 if (state == views::CustomButton::BS_HOT) | 436 if (state == views::CustomButton::BS_HOT) |
433 canvas.FillRect(gfx::Rect(size()), SkColorSetARGB(64, 255, 255, 255)); | 437 canvas.FillRect(gfx::Rect(size()), SkColorSetARGB(64, 255, 255, 255)); |
434 | 438 |
435 return SkBitmapOperations::CreateMaskedBitmap(canvas.ExtractBitmap(), *mask); | 439 return gfx::ImageSkiaOperations::CreateMaskedImage( |
| 440 gfx::ImageSkia(canvas.ExtractImageSkiaRep()), *mask); |
436 } | 441 } |
437 | 442 |
438 SkBitmap NewTabButton::GetBitmapForState( | 443 gfx::ImageSkia NewTabButton::GetImageForState( |
439 views::CustomButton::ButtonState state) const { | 444 views::CustomButton::ButtonState state, |
| 445 ui::ScaleFactor scale_factor) const { |
440 int overlay_id = 0; | 446 int overlay_id = 0; |
441 // The new tab button field trial will get created in variations_service.cc | 447 // The new tab button field trial will get created in variations_service.cc |
442 // through the variations server. | 448 // through the variations server. |
443 if (base::FieldTrialList::FindFullName(kNewTabButtonFieldTrialName) == | 449 if (base::FieldTrialList::FindFullName(kNewTabButtonFieldTrialName) == |
444 kNewTabButtonFieldTrialPlusGroupName) { | 450 kNewTabButtonFieldTrialPlusGroupName) { |
445 overlay_id = state == views::CustomButton::BS_PUSHED ? | 451 overlay_id = state == views::CustomButton::BS_PUSHED ? |
446 IDR_NEWTAB_BUTTON_P_PLUS : IDR_NEWTAB_BUTTON_PLUS; | 452 IDR_NEWTAB_BUTTON_P_PLUS : IDR_NEWTAB_BUTTON_PLUS; |
447 } else { | 453 } else { |
448 overlay_id = state == views::CustomButton::BS_PUSHED ? | 454 overlay_id = state == views::CustomButton::BS_PUSHED ? |
449 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; | 455 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; |
450 } | 456 } |
451 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); | 457 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); |
452 | 458 |
453 gfx::Canvas canvas(gfx::Size(overlay->width(), overlay->height()), false); | 459 gfx::Canvas canvas( |
454 canvas.DrawImageInt(GetBackgroundBitmap(state), 0, 0); | 460 gfx::Size(overlay->width(), overlay->height()), scale_factor, false); |
| 461 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); |
455 | 462 |
456 // Draw the button border with a slight alpha. | 463 // Draw the button border with a slight alpha. |
457 const int kNativeFrameOverlayAlpha = 178; | 464 const int kNativeFrameOverlayAlpha = 178; |
458 const int kOpaqueFrameOverlayAlpha = 230; | 465 const int kOpaqueFrameOverlayAlpha = 230; |
459 canvas.SaveLayerAlpha(ShouldUseNativeFrame() ? | 466 canvas.SaveLayerAlpha(ShouldUseNativeFrame() ? |
460 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha); | 467 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha); |
461 canvas.DrawImageInt(*overlay, 0, 0); | 468 canvas.DrawImageInt(*overlay, 0, 0); |
462 canvas.Restore(); | 469 canvas.Restore(); |
463 | 470 |
464 return canvas.ExtractBitmap(); | 471 return gfx::ImageSkia(canvas.ExtractImageSkiaRep()); |
465 } | 472 } |
466 | 473 |
467 SkBitmap NewTabButton::GetBitmap() const { | 474 gfx::ImageSkia NewTabButton::GetImage(ui::ScaleFactor scale_factor) const { |
468 if (!hover_animation_->is_animating()) | 475 if (!hover_animation_->is_animating()) |
469 return GetBitmapForState(state()); | 476 return GetImageForState(state(), scale_factor); |
470 return SkBitmapOperations::CreateBlendedBitmap( | 477 return gfx::ImageSkiaOperations::CreateBlendedImage( |
471 GetBitmapForState(views::CustomButton::BS_NORMAL), | 478 GetImageForState(views::CustomButton::BS_NORMAL, scale_factor), |
472 GetBitmapForState(views::CustomButton::BS_HOT), | 479 GetImageForState(views::CustomButton::BS_HOT, scale_factor), |
473 hover_animation_->GetCurrentValue()); | 480 hover_animation_->GetCurrentValue()); |
474 } | 481 } |
475 | 482 |
476 /////////////////////////////////////////////////////////////////////////////// | 483 /////////////////////////////////////////////////////////////////////////////// |
477 // TabStrip::RemoveTabDelegate | 484 // TabStrip::RemoveTabDelegate |
478 // | 485 // |
479 // AnimationDelegate used when removing a tab. Does the necessary cleanup when | 486 // AnimationDelegate used when removing a tab. Does the necessary cleanup when |
480 // done. | 487 // done. |
481 class TabStrip::RemoveTabDelegate | 488 class TabStrip::RemoveTabDelegate |
482 : public views::BoundsAnimator::OwnedAnimationDelegate { | 489 : public views::BoundsAnimator::OwnedAnimationDelegate { |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2335 | 2342 |
2336 int mini_tab_count = GetMiniTabCount(); | 2343 int mini_tab_count = GetMiniTabCount(); |
2337 int normal_count = tab_count() - mini_tab_count; | 2344 int normal_count = tab_count() - mini_tab_count; |
2338 if (normal_count == 0 || normal_count == mini_tab_count) | 2345 if (normal_count == 0 || normal_count == mini_tab_count) |
2339 return false; | 2346 return false; |
2340 int x = GetStartXForNormalTabs(); | 2347 int x = GetStartXForNormalTabs(); |
2341 int available_width = width() - x - new_tab_button_width(); | 2348 int available_width = width() - x - new_tab_button_width(); |
2342 return (Tab::GetTouchWidth() * normal_count + | 2349 return (Tab::GetTouchWidth() * normal_count + |
2343 tab_h_offset() * (normal_count - 1)) > available_width; | 2350 tab_h_offset() * (normal_count - 1)) > available_width; |
2344 } | 2351 } |
OLD | NEW |