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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "win8/util/win8_util.h" | 62 #include "win8/util/win8_util.h" |
63 #endif | 63 #endif |
64 | 64 |
65 using base::UserMetricsAction; | 65 using base::UserMetricsAction; |
66 using ui::DropTargetEvent; | 66 using ui::DropTargetEvent; |
67 | 67 |
68 namespace { | 68 namespace { |
69 | 69 |
70 static const int kTabStripAnimationVSlop = 40; | 70 static const int kTabStripAnimationVSlop = 40; |
71 // Inactive tabs in a native frame are slightly transparent. | 71 // Inactive tabs in a native frame are slightly transparent. |
72 static const int kNativeFrameInactiveTabAlpha = 200; | 72 static const int kGlassFrameInactiveTabAlpha = 200; |
73 // If there are multiple tabs selected then make non-selected inactive tabs | 73 // If there are multiple tabs selected then make non-selected inactive tabs |
74 // even more transparent. | 74 // even more transparent. |
75 static const int kNativeFrameInactiveTabAlphaMultiSelection = 150; | 75 static const int kGlassFrameInactiveTabAlphaMultiSelection = 150; |
76 | 76 |
77 // Alpha applied to all elements save the selected tabs. | 77 // Alpha applied to all elements save the selected tabs. |
78 static const int kInactiveTabAndNewTabButtonAlphaAsh = 230; | 78 static const int kInactiveTabAndNewTabButtonAlphaAsh = 230; |
79 static const int kInactiveTabAndNewTabButtonAlpha = 255; | 79 static const int kInactiveTabAndNewTabButtonAlpha = 255; |
80 | 80 |
81 // Inverse ratio of the width of a tab edge to the width of the tab. When | 81 // Inverse ratio of the width of a tab edge to the width of the tab. When |
82 // hovering over the left or right edge of a tab, the drop indicator will | 82 // hovering over the left or right edge of a tab, the drop indicator will |
83 // point between tabs. | 83 // point between tabs. |
84 static const int kTabEdgeRatioInverse = 4; | 84 static const int kTabEdgeRatioInverse = 4; |
85 | 85 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 gfx::Path* path) const OVERRIDE; | 326 gfx::Path* path) const OVERRIDE; |
327 #if defined(OS_WIN) | 327 #if defined(OS_WIN) |
328 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 328 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
329 #endif | 329 #endif |
330 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 330 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
331 | 331 |
332 // Overridden from ui::EventHandler: | 332 // Overridden from ui::EventHandler: |
333 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 333 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
334 | 334 |
335 private: | 335 private: |
336 bool ShouldUseNativeFrame() const; | 336 bool ShouldWindowContentsBeTransparent() const; |
337 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, | 337 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, |
338 ui::ScaleFactor scale_factor) const; | 338 ui::ScaleFactor scale_factor) const; |
339 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, | 339 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, |
340 ui::ScaleFactor scale_factor) const; | 340 ui::ScaleFactor scale_factor) const; |
341 gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const; | 341 gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const; |
342 | 342 |
343 // Tab strip that contains this button. | 343 // Tab strip that contains this button. |
344 TabStrip* tab_strip_; | 344 TabStrip* tab_strip_; |
345 | 345 |
346 // The offset used to paint the background image. | 346 // The offset used to paint the background image. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 canvas->DrawImageInt(image, 0, height() - image.height()); | 420 canvas->DrawImageInt(image, 0, height() - image.height()); |
421 } | 421 } |
422 | 422 |
423 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { | 423 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { |
424 // Consume all gesture events here so that the parent (Tab) does not | 424 // Consume all gesture events here so that the parent (Tab) does not |
425 // start consuming gestures. | 425 // start consuming gestures. |
426 views::ImageButton::OnGestureEvent(event); | 426 views::ImageButton::OnGestureEvent(event); |
427 event->SetHandled(); | 427 event->SetHandled(); |
428 } | 428 } |
429 | 429 |
430 bool NewTabButton::ShouldUseNativeFrame() const { | 430 bool NewTabButton::ShouldWindowContentsBeTransparent() const { |
431 return GetWidget() && | 431 return GetWidget() && |
432 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); | 432 GetWidget()->GetTopLevelWidget()->ShouldWindowContentsBeTransparent(); |
433 } | 433 } |
434 | 434 |
435 gfx::ImageSkia NewTabButton::GetBackgroundImage( | 435 gfx::ImageSkia NewTabButton::GetBackgroundImage( |
436 views::CustomButton::ButtonState state, | 436 views::CustomButton::ButtonState state, |
437 ui::ScaleFactor scale_factor) const { | 437 ui::ScaleFactor scale_factor) const { |
438 int background_id = 0; | 438 int background_id = 0; |
439 if (ShouldUseNativeFrame()) { | 439 if (ShouldWindowContentsBeTransparent()) { |
440 background_id = IDR_THEME_TAB_BACKGROUND_V; | 440 background_id = IDR_THEME_TAB_BACKGROUND_V; |
441 } else if (tab_strip_->controller()->IsIncognito()) { | 441 } else if (tab_strip_->controller()->IsIncognito()) { |
442 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | 442 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
443 #if defined(OS_WIN) | 443 #if defined(OS_WIN) |
444 } else if (win8::IsSingleWindowMetroMode()) { | 444 } else if (win8::IsSingleWindowMetroMode()) { |
445 background_id = IDR_THEME_TAB_BACKGROUND_V; | 445 background_id = IDR_THEME_TAB_BACKGROUND_V; |
446 #endif | 446 #endif |
447 } else { | 447 } else { |
448 background_id = IDR_THEME_TAB_BACKGROUND; | 448 background_id = IDR_THEME_TAB_BACKGROUND; |
449 } | 449 } |
450 | 450 |
451 int alpha = 0; | 451 int alpha = 0; |
452 switch (state) { | 452 switch (state) { |
453 case views::CustomButton::STATE_NORMAL: | 453 case views::CustomButton::STATE_NORMAL: |
454 case views::CustomButton::STATE_HOVERED: | 454 case views::CustomButton::STATE_HOVERED: |
455 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; | 455 alpha = ShouldWindowContentsBeTransparent() ? kGlassFrameInactiveTabAlpha |
| 456 : 255; |
456 break; | 457 break; |
457 case views::CustomButton::STATE_PRESSED: | 458 case views::CustomButton::STATE_PRESSED: |
458 alpha = 145; | 459 alpha = 145; |
459 break; | 460 break; |
460 default: | 461 default: |
461 NOTREACHED(); | 462 NOTREACHED(); |
462 break; | 463 break; |
463 } | 464 } |
464 | 465 |
465 gfx::ImageSkia* mask = | 466 gfx::ImageSkia* mask = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; | 517 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; |
517 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); | 518 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); |
518 | 519 |
519 gfx::Canvas canvas( | 520 gfx::Canvas canvas( |
520 gfx::Size(overlay->width(), overlay->height()), | 521 gfx::Size(overlay->width(), overlay->height()), |
521 ui::GetImageScale(scale_factor), | 522 ui::GetImageScale(scale_factor), |
522 false); | 523 false); |
523 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); | 524 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); |
524 | 525 |
525 // Draw the button border with a slight alpha. | 526 // Draw the button border with a slight alpha. |
526 const int kNativeFrameOverlayAlpha = 178; | 527 const int kGlassFrameOverlayAlpha = 178; |
527 const int kOpaqueFrameOverlayAlpha = 230; | 528 const int kOpaqueFrameOverlayAlpha = 230; |
528 uint8 alpha = ShouldUseNativeFrame() ? | 529 uint8 alpha = ShouldWindowContentsBeTransparent() ? |
529 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; | 530 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; |
530 canvas.DrawImageInt(*overlay, 0, 0, alpha); | 531 canvas.DrawImageInt(*overlay, 0, 0, alpha); |
531 | 532 |
532 return gfx::ImageSkia(canvas.ExtractImageRep()); | 533 return gfx::ImageSkia(canvas.ExtractImageRep()); |
533 } | 534 } |
534 | 535 |
535 gfx::ImageSkia NewTabButton::GetImageForScale( | 536 gfx::ImageSkia NewTabButton::GetImageForScale( |
536 ui::ScaleFactor scale_factor) const { | 537 ui::ScaleFactor scale_factor) const { |
537 if (!hover_animation_->is_animating()) | 538 if (!hover_animation_->is_animating()) |
538 return GetImageForState(state(), scale_factor); | 539 return GetImageForState(state(), scale_factor); |
539 return gfx::ImageSkiaOperations::CreateBlendedImage( | 540 return gfx::ImageSkiaOperations::CreateBlendedImage( |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 } | 1326 } |
1326 | 1327 |
1327 for (int i = tab_count() - 1; i > active_tab_index; --i) { | 1328 for (int i = tab_count() - 1; i > active_tab_index; --i) { |
1328 Tab* tab = tab_at(i); | 1329 Tab* tab = tab_at(i); |
1329 tab->Paint(canvas); | 1330 tab->Paint(canvas); |
1330 } | 1331 } |
1331 } | 1332 } |
1332 if (inactive_tab_alpha < 255) | 1333 if (inactive_tab_alpha < 255) |
1333 canvas->Restore(); | 1334 canvas->Restore(); |
1334 | 1335 |
1335 if (GetWidget()->ShouldUseNativeFrame()) { | 1336 if (GetWidget()->ShouldWindowContentsBeTransparent()) { |
1336 // Make sure non-active tabs are somewhat transparent. | 1337 // Make sure non-active tabs are somewhat transparent. |
1337 SkPaint paint; | 1338 SkPaint paint; |
1338 // If there are multiple tabs selected, fade non-selected tabs more to make | 1339 // If there are multiple tabs selected, fade non-selected tabs more to make |
1339 // the selected tabs more noticable. | 1340 // the selected tabs more noticable. |
1340 int alpha = selected_tab_count > 1 ? | 1341 int alpha = selected_tab_count > 1 ? |
1341 kNativeFrameInactiveTabAlphaMultiSelection : | 1342 kGlassFrameInactiveTabAlphaMultiSelection : |
1342 kNativeFrameInactiveTabAlpha; | 1343 kGlassFrameInactiveTabAlpha; |
1343 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); | 1344 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
1344 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 1345 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
1345 paint.setStyle(SkPaint::kFill_Style); | 1346 paint.setStyle(SkPaint::kFill_Style); |
1346 // The tabstrip area overlaps the toolbar area by 2 px. | 1347 // The tabstrip area overlaps the toolbar area by 2 px. |
1347 canvas->DrawRect(gfx::Rect(0, 0, width(), height() - 2), paint); | 1348 canvas->DrawRect(gfx::Rect(0, 0, width(), height() - 2), paint); |
1348 } | 1349 } |
1349 | 1350 |
1350 // Now selected but not active. We don't want these dimmed if using native | 1351 // Now selected but not active. We don't want these dimmed if using native |
1351 // frame, so they're painted after initial pass. | 1352 // frame, so they're painted after initial pass. |
1352 for (size_t i = 0; i < selected_tabs.size(); ++i) | 1353 for (size_t i = 0; i < selected_tabs.size(); ++i) |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 #if defined(USE_AURA) | 2774 #if defined(USE_AURA) |
2774 return chrome::GetHostDesktopTypeForNativeView( | 2775 return chrome::GetHostDesktopTypeForNativeView( |
2775 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; | 2776 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; |
2776 #else | 2777 #else |
2777 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2778 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2778 return false; | 2779 return false; |
2779 #endif | 2780 #endif |
2780 | 2781 |
2781 return true; | 2782 return true; |
2782 } | 2783 } |
OLD | NEW |