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

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

Issue 2821011: Removes phantom tabs. (Closed)
Patch Set: Created 10 years, 6 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
« no previous file with comments | « chrome/browser/views/tabs/tab_strip.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/tabs/tab_strip.h" 5 #include "chrome/browser/views/tabs/tab_strip.h"
6 6
7 #include "app/animation_container.h" 7 #include "app/animation_container.h"
8 #include "app/drag_drop_types.h" 8 #include "app/drag_drop_types.h"
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // until the user can actually see the tab. 62 // until the user can actually see the tab.
63 static const int kNetTabSelectedOffset = -13; 63 static const int kNetTabSelectedOffset = -13;
64 64
65 static const int kNewTabButtonHOffset = -5; 65 static const int kNewTabButtonHOffset = -5;
66 static const int kNewTabButtonVOffset = 5; 66 static const int kNewTabButtonVOffset = 5;
67 static const int kResizeTabsTimeMs = 300; 67 static const int kResizeTabsTimeMs = 300;
68 static const int kSuspendAnimationsTimeMs = 200; 68 static const int kSuspendAnimationsTimeMs = 200;
69 static const int kTabHOffset = -16; 69 static const int kTabHOffset = -16;
70 static const int kTabStripAnimationVSlop = 40; 70 static const int kTabStripAnimationVSlop = 40;
71 71
72 // Alpha value phantom tabs are rendered at.
73 static const int kPhantomTabAlpha = 105;
74
75 // Alpha value phantom tab icons are rendered at.
76 static const int kPhantomTabIconAlpha = 160;
77
78 // Size of the drop indicator. 72 // Size of the drop indicator.
79 static int drop_indicator_width; 73 static int drop_indicator_width;
80 static int drop_indicator_height; 74 static int drop_indicator_height;
81 75
82 static inline int Round(double x) { 76 static inline int Round(double x) {
83 // Why oh why is this not in a standard header? 77 // Why oh why is this not in a standard header?
84 return static_cast<int>(floor(x + 0.5)); 78 return static_cast<int>(floor(x + 0.5));
85 } 79 }
86 80
87 namespace { 81 namespace {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // do this as during dragging there isn't a theme provider. 317 // do this as during dragging there isn't a theme provider.
324 tab->set_theme_provider(GetThemeProvider()); 318 tab->set_theme_provider(GetThemeProvider());
325 return tab; 319 return tab;
326 } 320 }
327 321
328 /////////////////////////////////////////////////////////////////////////////// 322 ///////////////////////////////////////////////////////////////////////////////
329 // TabStrip, views::View overrides: 323 // TabStrip, views::View overrides:
330 324
331 void TabStrip::PaintChildren(gfx::Canvas* canvas) { 325 void TabStrip::PaintChildren(gfx::Canvas* canvas) {
332 // Tabs are painted in reverse order, so they stack to the left. 326 // Tabs are painted in reverse order, so they stack to the left.
333 // Phantom tabs appear behind all other tabs and are rendered first. To make
334 // them slightly transparent we render them to a different layer.
335 if (HasPhantomTabs()) {
336 SkRect bounds;
337 bounds.set(0, 0, SkIntToScalar(width()), SkIntToScalar(height()));
338 canvas->saveLayerAlpha(&bounds, kPhantomTabAlpha,
339 SkCanvas::kARGB_ClipLayer_SaveFlag);
340 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
341 for (int i = tab_count() - 1; i >= 0; --i) {
342 Tab* tab = GetTabAtTabDataIndex(i);
343 if (tab->data().phantom)
344 tab->ProcessPaint(canvas);
345 }
346 canvas->restore();
347
348 canvas->saveLayerAlpha(&bounds, kPhantomTabIconAlpha,
349 SkCanvas::kARGB_ClipLayer_SaveFlag);
350 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
351 for (int i = tab_count() - 1; i >= 0; --i) {
352 Tab* tab = GetTabAtTabDataIndex(i);
353 if (tab->data().phantom) {
354 canvas->save();
355 canvas->ClipRectInt(tab->MirroredX(), tab->y(), tab->width(),
356 tab->height());
357 canvas->TranslateInt(tab->MirroredX(), tab->y());
358 tab->PaintIcon(canvas);
359 canvas->restore();
360 }
361 }
362 canvas->restore();
363 }
364
365 Tab* selected_tab = NULL; 327 Tab* selected_tab = NULL;
366 328
367 Tab* dragging_tab = NULL; 329 Tab* dragging_tab = NULL;
368 330
369 int model_count = GetModelCount(); 331 int model_count = GetModelCount();
370 332
371 for (int i = tab_count() - 1; i >= 0; --i) { 333 for (int i = tab_count() - 1; i >= 0; --i) {
372 Tab* tab = GetTabAtTabDataIndex(i); 334 Tab* tab = GetTabAtTabDataIndex(i);
373 // We must ask the _Tab's_ model, not ourselves, because in some situations 335 // We must ask the _Tab's_ model, not ourselves, because in some situations
374 // the model will be different to this object, e.g. when a Tab is being 336 // the model will be different to this object, e.g. when a Tab is being
375 // removed after its TabContents has been destroyed. 337 // removed after its TabContents has been destroyed.
376 if (!tab->data().phantom) { 338 if (tab->dragging()) {
377 if (tab->dragging()) { 339 dragging_tab = tab;
378 dragging_tab = tab; 340 } else if (!tab->IsSelected()) {
379 } else if (!tab->IsSelected()) { 341 if (tab->render_unselected() && model_count > 1) {
380 if (tab->render_unselected() && model_count > 1) { 342 // See comment above kNetTabAnimationSelectedOffset as to why we do
381 // See comment above kNetTabAnimationSelectedOffset as to why we do 343 // this.
382 // this. 344 Tab* last_tab = GetTabAtModelIndex(model_count - 2);
383 Tab* last_tab = GetTabAtModelIndex(model_count - 2); 345 canvas->save();
384 canvas->save(); 346 int clip_x = last_tab->bounds().right() + kNetTabSelectedOffset;
385 int clip_x = last_tab->bounds().right() + kNetTabSelectedOffset; 347 int clip_width = width() - clip_x;
386 int clip_width = width() - clip_x; 348 clip_x = MirroredXWithWidthInsideView(clip_x, clip_width);
387 clip_x = MirroredXWithWidthInsideView(clip_x, clip_width); 349 canvas->ClipRectInt(clip_x, 0, clip_width, height());
388 canvas->ClipRectInt(clip_x, 0, clip_width, height()); 350 tab->ProcessPaint(canvas);
389 tab->ProcessPaint(canvas); 351 canvas->restore();
390 canvas->restore();
391 } else {
392 tab->ProcessPaint(canvas);
393 }
394 } else { 352 } else {
395 selected_tab = tab; 353 tab->ProcessPaint(canvas);
396 } 354 }
355 } else {
356 selected_tab = tab;
397 } 357 }
398 } 358 }
399 359
400 if (GetWindow()->GetNonClientView()->UseNativeFrame()) { 360 if (GetWindow()->GetNonClientView()->UseNativeFrame()) {
401 // Make sure unselected tabs are somewhat transparent. 361 // Make sure unselected tabs are somewhat transparent.
402 SkPaint paint; 362 SkPaint paint;
403 paint.setColor(SkColorSetARGB(200, 255, 255, 255)); 363 paint.setColor(SkColorSetARGB(200, 255, 255, 255));
404 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 364 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
405 paint.setStyle(SkPaint::kFill_Style); 365 paint.setStyle(SkPaint::kFill_Style);
406 canvas->FillRectInt( 366 canvas->FillRectInt(
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 &TabStrip::ResizeLayoutTabs), 1316 &TabStrip::ResizeLayoutTabs),
1357 kResizeTabsTimeMs); 1317 kResizeTabsTimeMs);
1358 } 1318 }
1359 } else { 1319 } else {
1360 // Mouse moved quickly out of the tab strip and then into it again, so 1320 // Mouse moved quickly out of the tab strip and then into it again, so
1361 // cancel the timer so that the strip doesn't move when the mouse moves 1321 // cancel the timer so that the strip doesn't move when the mouse moves
1362 // back over it. 1322 // back over it.
1363 resize_layout_factory_.RevokeAll(); 1323 resize_layout_factory_.RevokeAll();
1364 } 1324 }
1365 } 1325 }
1366
1367 bool TabStrip::HasPhantomTabs() const {
1368 for (int i = 0; i < tab_count(); ++i) {
1369 if (GetTabAtTabDataIndex(i)->data().phantom)
1370 return true;
1371 }
1372 return false;
1373 }
OLDNEW
« no previous file with comments | « chrome/browser/views/tabs/tab_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698