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.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 button_color_(SK_ColorTRANSPARENT) { | 383 button_color_(SK_ColorTRANSPARENT) { |
384 DCHECK(controller); | 384 DCHECK(controller); |
385 InitTabResources(); | 385 InitTabResources(); |
386 | 386 |
387 // So we get don't get enter/exit on children and don't prematurely stop the | 387 // So we get don't get enter/exit on children and don't prematurely stop the |
388 // hover. | 388 // hover. |
389 set_notify_enter_exit_on_child(true); | 389 set_notify_enter_exit_on_child(true); |
390 | 390 |
391 set_id(VIEW_ID_TAB); | 391 set_id(VIEW_ID_TAB); |
392 | 392 |
| 393 SetBorder(views::Border::CreateEmptyBorder(GetLayoutInsets(TAB))); |
| 394 |
393 title_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | 395 title_->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
394 title_->SetElideBehavior(gfx::FADE_TAIL); | 396 title_->SetElideBehavior(gfx::FADE_TAIL); |
395 title_->SetHandlesTooltips(false); | 397 title_->SetHandlesTooltips(false); |
396 title_->SetAutoColorReadabilityEnabled(false); | 398 title_->SetAutoColorReadabilityEnabled(false); |
397 title_->SetText(CoreTabHelper::GetDefaultTitle()); | 399 title_->SetText(CoreTabHelper::GetDefaultTitle()); |
398 AddChildView(title_); | 400 AddChildView(title_); |
399 | 401 |
400 SetEventTargeter( | 402 SetEventTargeter( |
401 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 403 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
402 | 404 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 if (controller_->IsImmersiveStyle()) | 774 if (controller_->IsImmersiveStyle()) |
773 PaintImmersiveTab(canvas); | 775 PaintImmersiveTab(canvas); |
774 else | 776 else |
775 PaintTab(canvas); | 777 PaintTab(canvas); |
776 | 778 |
777 if (!clip.IsEmpty()) | 779 if (!clip.IsEmpty()) |
778 canvas->Restore(); | 780 canvas->Restore(); |
779 } | 781 } |
780 | 782 |
781 void Tab::Layout() { | 783 void Tab::Layout() { |
782 gfx::Rect lb = GetInteriorBounds(); | 784 gfx::Rect lb = GetContentsBounds(); |
783 if (lb.IsEmpty()) | 785 if (lb.IsEmpty()) |
784 return; | 786 return; |
785 | 787 |
786 showing_icon_ = ShouldShowIcon(); | 788 showing_icon_ = ShouldShowIcon(); |
787 // See comments in IconCapacity(). | 789 // See comments in IconCapacity(). |
788 const int extra_padding = | 790 const int extra_padding = |
789 (controller_->ShouldHideCloseButtonForInactiveTabs() || | 791 (controller_->ShouldHideCloseButtonForInactiveTabs() || |
790 (IconCapacity() < 3)) ? 0 : kExtraLeftPaddingToBalanceCloseButtonPadding; | 792 (IconCapacity() < 3)) ? 0 : kExtraLeftPaddingToBalanceCloseButtonPadding; |
791 const int start = lb.x() + extra_padding; | 793 const int start = lb.x() + extra_padding; |
792 favicon_bounds_.SetRect(start, lb.y(), 0, 0); | 794 favicon_bounds_.SetRect(start, lb.y(), 0, 0); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 canvas->DrawImageInt(*tab_image->image_l, 0, 0); | 1341 canvas->DrawImageInt(*tab_image->image_l, 0, 0); |
1340 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, | 1342 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, 0, |
1341 width() - tab_image->l_width - tab_image->r_width, height()); | 1343 width() - tab_image->l_width - tab_image->r_width, height()); |
1342 canvas->DrawImageInt(*tab_image->image_r, width() - tab_image->r_width, 0); | 1344 canvas->DrawImageInt(*tab_image->image_r, width() - tab_image->r_width, 0); |
1343 } | 1345 } |
1344 | 1346 |
1345 void Tab::PaintIcon(gfx::Canvas* canvas) { | 1347 void Tab::PaintIcon(gfx::Canvas* canvas) { |
1346 gfx::Rect bounds = favicon_bounds_; | 1348 gfx::Rect bounds = favicon_bounds_; |
1347 bounds.set_x(GetMirroredXForRect(bounds)); | 1349 bounds.set_x(GetMirroredXForRect(bounds)); |
1348 bounds.Offset(0, favicon_hiding_offset_); | 1350 bounds.Offset(0, favicon_hiding_offset_); |
1349 bounds.Intersect(GetInteriorBounds()); | 1351 bounds.Intersect(GetContentsBounds()); |
1350 if (bounds.IsEmpty()) | 1352 if (bounds.IsEmpty()) |
1351 return; | 1353 return; |
1352 | 1354 |
1353 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 1355 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
1354 // Paint network activity (aka throbber) animation frame. | 1356 // Paint network activity (aka throbber) animation frame. |
1355 ui::ThemeProvider* tp = GetThemeProvider(); | 1357 ui::ThemeProvider* tp = GetThemeProvider(); |
1356 if (data().network_state == TabRendererData::NETWORK_STATE_WAITING) { | 1358 if (data().network_state == TabRendererData::NETWORK_STATE_WAITING) { |
1357 if (waiting_start_time_ == base::TimeTicks()) | 1359 if (waiting_start_time_ == base::TimeTicks()) |
1358 waiting_start_time_ = base::TimeTicks::Now(); | 1360 waiting_start_time_ = base::TimeTicks::Now(); |
1359 | 1361 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 if (bounds.IsEmpty()) | 1516 if (bounds.IsEmpty()) |
1515 return; | 1517 return; |
1516 | 1518 |
1517 // Extends the area to the bottom when the crash animation is in progress. | 1519 // Extends the area to the bottom when the crash animation is in progress. |
1518 if (crash_icon_animation_) | 1520 if (crash_icon_animation_) |
1519 bounds.set_height(height() - bounds.y()); | 1521 bounds.set_height(height() - bounds.y()); |
1520 bounds.set_x(GetMirroredXForRect(bounds)); | 1522 bounds.set_x(GetMirroredXForRect(bounds)); |
1521 SchedulePaintInRect(bounds); | 1523 SchedulePaintInRect(bounds); |
1522 } | 1524 } |
1523 | 1525 |
1524 gfx::Rect Tab::GetInteriorBounds() const { | |
1525 gfx::Rect bounds(GetContentsBounds()); | |
1526 bounds.Inset(GetLayoutInsets(TAB)); | |
1527 return bounds; | |
1528 } | |
1529 | |
1530 gfx::Rect Tab::GetImmersiveBarRect() const { | 1526 gfx::Rect Tab::GetImmersiveBarRect() const { |
1531 // The main bar is as wide as the normal tab's horizontal top line. | 1527 // The main bar is as wide as the normal tab's horizontal top line. |
1532 // This top line of the tab extends a few pixels left and right of the | 1528 // This top line of the tab extends a few pixels left and right of the |
1533 // center image due to pixels in the rounded corner images. | 1529 // center image due to pixels in the rounded corner images. |
1534 const int kBarPadding = 1; | 1530 const int kBarPadding = 1; |
1535 int main_bar_left = tab_active_.l_width - kBarPadding; | 1531 int main_bar_left = tab_active_.l_width - kBarPadding; |
1536 int main_bar_right = width() - tab_active_.r_width + kBarPadding; | 1532 int main_bar_right = width() - tab_active_.r_width + kBarPadding; |
1537 return gfx::Rect( | 1533 return gfx::Rect( |
1538 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); | 1534 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
1539 } | 1535 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 const gfx::ImageSkia& image) { | 1607 const gfx::ImageSkia& image) { |
1612 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1608 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
1613 ImageCacheEntry entry; | 1609 ImageCacheEntry entry; |
1614 entry.resource_id = resource_id; | 1610 entry.resource_id = resource_id; |
1615 entry.scale_factor = scale_factor; | 1611 entry.scale_factor = scale_factor; |
1616 entry.image = image; | 1612 entry.image = image; |
1617 image_cache_->push_front(entry); | 1613 image_cache_->push_front(entry); |
1618 if (image_cache_->size() > kMaxImageCacheSize) | 1614 if (image_cache_->size() > kMaxImageCacheSize) |
1619 image_cache_->pop_back(); | 1615 image_cache_->pop_back(); |
1620 } | 1616 } |
OLD | NEW |