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

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

Issue 136093007: Widget::ShouldUseNativeFrame is now meaningful on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 10 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 | Annotate | Revision Log
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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 kNativeFrameInactiveTabAlpha = 200;
73 #if defined(OS_WIN)
73 // If there are multiple tabs selected then make non-selected inactive tabs 74 // If there are multiple tabs selected then make non-selected inactive tabs
74 // even more transparent. 75 // even more transparent.
75 static const int kNativeFrameInactiveTabAlphaMultiSelection = 150; 76 static const int kNativeFrameInactiveTabAlphaMultiSelection = 150;
sky 2014/02/03 21:53:03 Rename this to better match other naming.
Matt Giuca 2014/02/05 23:25:31 Done.
77 #endif
76 78
77 // Alpha applied to all elements save the selected tabs. 79 // Alpha applied to all elements save the selected tabs.
78 static const int kInactiveTabAndNewTabButtonAlphaAsh = 230; 80 static const int kInactiveTabAndNewTabButtonAlphaAsh = 230;
79 static const int kInactiveTabAndNewTabButtonAlpha = 255; 81 static const int kInactiveTabAndNewTabButtonAlpha = 255;
80 82
81 // Inverse ratio of the width of a tab edge to the width of the tab. When 83 // 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 84 // hovering over the left or right edge of a tab, the drop indicator will
83 // point between tabs. 85 // point between tabs.
84 static const int kTabEdgeRatioInverse = 4; 86 static const int kTabEdgeRatioInverse = 4;
85 87
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 gfx::Path* path) const OVERRIDE; 328 gfx::Path* path) const OVERRIDE;
327 #if defined(OS_WIN) 329 #if defined(OS_WIN)
328 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 330 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
329 #endif 331 #endif
330 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 332 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
331 333
332 // Overridden from ui::EventHandler: 334 // Overridden from ui::EventHandler:
333 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 335 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
334 336
335 private: 337 private:
336 bool ShouldUseNativeFrame() const; 338 // Returns true on Windows if the Glass styling is being used.
339 // This implies that the tab strip overlaps a native window frame.
340 bool UsingWindowsGlass() const;
337 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, 341 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state,
338 ui::ScaleFactor scale_factor) const; 342 ui::ScaleFactor scale_factor) const;
339 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, 343 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state,
340 ui::ScaleFactor scale_factor) const; 344 ui::ScaleFactor scale_factor) const;
341 gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const; 345 gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const;
342 346
343 // Tab strip that contains this button. 347 // Tab strip that contains this button.
344 TabStrip* tab_strip_; 348 TabStrip* tab_strip_;
345 349
346 // The offset used to paint the background image. 350 // The offset used to paint the background image.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 canvas->DrawImageInt(image, 0, height() - image.height()); 424 canvas->DrawImageInt(image, 0, height() - image.height());
421 } 425 }
422 426
423 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { 427 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) {
424 // Consume all gesture events here so that the parent (Tab) does not 428 // Consume all gesture events here so that the parent (Tab) does not
425 // start consuming gestures. 429 // start consuming gestures.
426 views::ImageButton::OnGestureEvent(event); 430 views::ImageButton::OnGestureEvent(event);
427 event->SetHandled(); 431 event->SetHandled();
428 } 432 }
429 433
430 bool NewTabButton::ShouldUseNativeFrame() const { 434 bool NewTabButton::UsingWindowsGlass() const {
435 #if defined(OS_WIN)
431 return GetWidget() && 436 return GetWidget() &&
432 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); 437 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame();
438 #endif
439 return false;
433 } 440 }
434 441
435 gfx::ImageSkia NewTabButton::GetBackgroundImage( 442 gfx::ImageSkia NewTabButton::GetBackgroundImage(
436 views::CustomButton::ButtonState state, 443 views::CustomButton::ButtonState state,
437 ui::ScaleFactor scale_factor) const { 444 ui::ScaleFactor scale_factor) const {
438 int background_id = 0; 445 int background_id = 0;
439 if (ShouldUseNativeFrame()) { 446 if (UsingWindowsGlass()) {
440 background_id = IDR_THEME_TAB_BACKGROUND_V; 447 background_id = IDR_THEME_TAB_BACKGROUND_V;
441 } else if (tab_strip_->controller()->IsIncognito()) { 448 } else if (tab_strip_->controller()->IsIncognito()) {
442 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; 449 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO;
443 #if defined(OS_WIN) 450 #if defined(OS_WIN)
444 } else if (win8::IsSingleWindowMetroMode()) { 451 } else if (win8::IsSingleWindowMetroMode()) {
445 background_id = IDR_THEME_TAB_BACKGROUND_V; 452 background_id = IDR_THEME_TAB_BACKGROUND_V;
446 #endif 453 #endif
447 } else { 454 } else {
448 background_id = IDR_THEME_TAB_BACKGROUND; 455 background_id = IDR_THEME_TAB_BACKGROUND;
449 } 456 }
450 457
451 int alpha = 0; 458 int alpha = 0;
452 switch (state) { 459 switch (state) {
453 case views::CustomButton::STATE_NORMAL: 460 case views::CustomButton::STATE_NORMAL:
454 case views::CustomButton::STATE_HOVERED: 461 case views::CustomButton::STATE_HOVERED:
455 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; 462 alpha = UsingWindowsGlass() ? kNativeFrameInactiveTabAlpha : 255;
456 break; 463 break;
457 case views::CustomButton::STATE_PRESSED: 464 case views::CustomButton::STATE_PRESSED:
458 alpha = 145; 465 alpha = 145;
459 break; 466 break;
460 default: 467 default:
461 NOTREACHED(); 468 NOTREACHED();
462 break; 469 break;
463 } 470 }
464 471
465 gfx::ImageSkia* mask = 472 gfx::ImageSkia* mask =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; 523 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
517 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); 524 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
518 525
519 gfx::Canvas canvas( 526 gfx::Canvas canvas(
520 gfx::Size(overlay->width(), overlay->height()), 527 gfx::Size(overlay->width(), overlay->height()),
521 ui::GetImageScale(scale_factor), 528 ui::GetImageScale(scale_factor),
522 false); 529 false);
523 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); 530 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0);
524 531
525 // Draw the button border with a slight alpha. 532 // Draw the button border with a slight alpha.
526 const int kNativeFrameOverlayAlpha = 178; 533 const int kNativeFrameOverlayAlpha = 178;
sky 2014/02/03 21:53:03 rename these too.
Matt Giuca 2014/02/05 23:25:31 Done.
527 const int kOpaqueFrameOverlayAlpha = 230; 534 const int kOpaqueFrameOverlayAlpha = 230;
528 uint8 alpha = ShouldUseNativeFrame() ? 535 uint8 alpha = UsingWindowsGlass() ?
529 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; 536 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha;
530 canvas.DrawImageInt(*overlay, 0, 0, alpha); 537 canvas.DrawImageInt(*overlay, 0, 0, alpha);
531 538
532 return gfx::ImageSkia(canvas.ExtractImageRep()); 539 return gfx::ImageSkia(canvas.ExtractImageRep());
533 } 540 }
534 541
535 gfx::ImageSkia NewTabButton::GetImageForScale( 542 gfx::ImageSkia NewTabButton::GetImageForScale(
536 ui::ScaleFactor scale_factor) const { 543 ui::ScaleFactor scale_factor) const {
537 if (!hover_animation_->is_animating()) 544 if (!hover_animation_->is_animating())
538 return GetImageForState(state(), scale_factor); 545 return GetImageForState(state(), scale_factor);
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 } 1332 }
1326 1333
1327 for (int i = tab_count() - 1; i > active_tab_index; --i) { 1334 for (int i = tab_count() - 1; i > active_tab_index; --i) {
1328 Tab* tab = tab_at(i); 1335 Tab* tab = tab_at(i);
1329 tab->Paint(canvas); 1336 tab->Paint(canvas);
1330 } 1337 }
1331 } 1338 }
1332 if (inactive_tab_alpha < 255) 1339 if (inactive_tab_alpha < 255)
1333 canvas->Restore(); 1340 canvas->Restore();
1334 1341
1342 #if defined(OS_WIN)
sky 2014/02/03 21:53:03 I would rather move the ifdef to a function with a
Matt Giuca 2014/02/05 23:25:31 Done.
1335 if (GetWidget()->ShouldUseNativeFrame()) { 1343 if (GetWidget()->ShouldUseNativeFrame()) {
1344 // On Windows, a native frame implies Glass.
1336 // Make sure non-active tabs are somewhat transparent. 1345 // Make sure non-active tabs are somewhat transparent.
1337 SkPaint paint; 1346 SkPaint paint;
1338 // If there are multiple tabs selected, fade non-selected tabs more to make 1347 // If there are multiple tabs selected, fade non-selected tabs more to make
1339 // the selected tabs more noticable. 1348 // the selected tabs more noticable.
1340 int alpha = selected_tab_count > 1 ? 1349 int alpha = selected_tab_count > 1 ?
1341 kNativeFrameInactiveTabAlphaMultiSelection : 1350 kNativeFrameInactiveTabAlphaMultiSelection :
1342 kNativeFrameInactiveTabAlpha; 1351 kNativeFrameInactiveTabAlpha;
1343 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); 1352 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255));
1344 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 1353 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
1345 paint.setStyle(SkPaint::kFill_Style); 1354 paint.setStyle(SkPaint::kFill_Style);
1346 // The tabstrip area overlaps the toolbar area by 2 px. 1355 // The tabstrip area overlaps the toolbar area by 2 px.
1347 canvas->DrawRect(gfx::Rect(0, 0, width(), height() - 2), paint); 1356 canvas->DrawRect(gfx::Rect(0, 0, width(), height() - 2), paint);
1348 } 1357 }
1358 #endif
1349 1359
1350 // Now selected but not active. We don't want these dimmed if using native 1360 // Now selected but not active. We don't want these dimmed if using native
1351 // frame, so they're painted after initial pass. 1361 // frame, so they're painted after initial pass.
1352 for (size_t i = 0; i < selected_tabs.size(); ++i) 1362 for (size_t i = 0; i < selected_tabs.size(); ++i)
1353 selected_tabs[i]->Paint(canvas); 1363 selected_tabs[i]->Paint(canvas);
1354 1364
1355 // Next comes the active tab. 1365 // Next comes the active tab.
1356 if (active_tab && !is_dragging) 1366 if (active_tab && !is_dragging)
1357 active_tab->Paint(canvas); 1367 active_tab->Paint(canvas);
1358 1368
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2773 #if defined(USE_AURA) 2783 #if defined(USE_AURA)
2774 return chrome::GetHostDesktopTypeForNativeView( 2784 return chrome::GetHostDesktopTypeForNativeView(
2775 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; 2785 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH;
2776 #else 2786 #else
2777 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) 2787 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH)
2778 return false; 2788 return false;
2779 #endif 2789 #endif
2780 2790
2781 return true; 2791 return true;
2782 } 2792 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698