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

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

Issue 1001003: Allow dynamic switching in and out of sidetabs mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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) 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/side_tab.h" 5 #include "chrome/browser/views/tabs/side_tab.h"
6 6
7 #include "app/gfx/canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/path.h" 8 #include "app/gfx/path.h"
9 #include "app/gfx/skia_util.h" 9 #include "app/gfx/skia_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 views::ImageButton* close_button = new views::ImageButton(this); 50 views::ImageButton* close_button = new views::ImageButton(this);
51 close_button->SetImage(views::CustomButton::BS_NORMAL, close_button_n_); 51 close_button->SetImage(views::CustomButton::BS_NORMAL, close_button_n_);
52 close_button->SetImage(views::CustomButton::BS_HOT, close_button_h_); 52 close_button->SetImage(views::CustomButton::BS_HOT, close_button_h_);
53 close_button->SetImage(views::CustomButton::BS_PUSHED, close_button_p_); 53 close_button->SetImage(views::CustomButton::BS_PUSHED, close_button_p_);
54 close_button_ = close_button; 54 close_button_ = close_button;
55 AddChildView(close_button_); 55 AddChildView(close_button_);
56 56
57 hover_animation_.reset(new SlideAnimation(this)); 57 hover_animation_.reset(new SlideAnimation(this));
58 hover_animation_->SetSlideDuration(kHoverDurationMs); 58 hover_animation_->SetSlideDuration(kHoverDurationMs);
59
60 SetContextMenuController(this);
59 } 61 }
60 62
61 SideTab::~SideTab() { 63 SideTab::~SideTab() {
62 } 64 }
63 65
64 void SideTab::SetNetworkState(SideTabStripModel::NetworkState state) { 66 void SideTab::SetNetworkState(SideTabStripModel::NetworkState state) {
65 if (current_state_ != state) { 67 if (current_state_ != state) {
66 // The waiting animation is the reverse of the loading animation, but at a 68 // The waiting animation is the reverse of the loading animation, but at a
67 // different rate - the following reverses and scales the animation_frame_ 69 // different rate - the following reverses and scales the animation_frame_
68 // so that the frame is at an equivalent position when going from one 70 // so that the frame is at an equivalent position when going from one
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 105
104 //////////////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////////////
105 // SideTab, views::ButtonListener implementation: 107 // SideTab, views::ButtonListener implementation:
106 108
107 void SideTab::ButtonPressed(views::Button* sender, const views::Event& event) { 109 void SideTab::ButtonPressed(views::Button* sender, const views::Event& event) {
108 DCHECK(sender == close_button_); 110 DCHECK(sender == close_button_);
109 model_->CloseTab(this); 111 model_->CloseTab(this);
110 } 112 }
111 113
112 //////////////////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////////////////
115 // SideTab, views::ContextMenuController implementation:
116
117 void SideTab::ShowContextMenu(views::View* source,
118 const gfx::Point& p,
119 bool is_mouse_gesture) {
120 model_->ShowContextMenu(this, p);
121 }
122
123 ////////////////////////////////////////////////////////////////////////////////
113 // SideTab, views::View overrides: 124 // SideTab, views::View overrides:
114 125
115 void SideTab::Layout() { 126 void SideTab::Layout() {
116 int icon_y; 127 int icon_y;
117 int icon_x = icon_y = (height() - kIconSize) / 2; 128 int icon_x = icon_y = (height() - kIconSize) / 2;
118 icon_bounds_.SetRect(icon_x, icon_y, kIconSize, kIconSize); 129 icon_bounds_.SetRect(icon_x, icon_y, kIconSize, kIconSize);
119 130
120 gfx::Size ps = close_button_->GetPreferredSize(); 131 gfx::Size ps = close_button_->GetPreferredSize();
121 int close_y = (height() - ps.height()) / 2; 132 int close_y = (height() - ps.height()) / 2;
122 close_button_->SetBounds(width() - ps.width() - close_y, close_y, ps.width(), 133 close_button_->SetBounds(
123 ps.height()); 134 std::max(0, width() - ps.width() - close_y),
135 close_y,
136 ps.width(),
137 ps.height());
124 138
125 int title_y = (height() - font_->height()) / 2; 139 int title_y = (height() - font_->height()) / 2;
126 int title_x = icon_bounds_.right() + kIconTitleSpacing; 140 int title_x = icon_bounds_.right() + kIconTitleSpacing;
127 title_bounds_.SetRect(title_x, title_y, 141 title_bounds_.SetRect(
128 close_button_->x() - kTitleCloseSpacing - title_x, 142 title_x,
129 font_->height()); 143 title_y,
144 std::max(0, close_button_->x() - kTitleCloseSpacing - title_x),
145 font_->height());
130 } 146 }
131 147
132 void SideTab::Paint(gfx::Canvas* canvas) { 148 void SideTab::Paint(gfx::Canvas* canvas) {
133 SkPaint paint; 149 SkPaint paint;
134 paint.setColor(kTabBackgroundColor); 150 paint.setColor(kTabBackgroundColor);
135 paint.setAntiAlias(true); 151 paint.setAntiAlias(true);
136 gfx::Path tab_shape; 152 gfx::Path tab_shape;
137 FillTabShapePath(&tab_shape); 153 FillTabShapePath(&tab_shape);
138 canvas->drawPath(tab_shape, paint); 154 canvas->drawPath(tab_shape, paint);
139 155
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 waiting_animation_frame_count = 266 waiting_animation_frame_count =
251 waiting_animation_frames->width() / waiting_animation_frames->height(); 267 waiting_animation_frames->width() / waiting_animation_frames->height();
252 268
253 waiting_to_loading_frame_count_ratio = 269 waiting_to_loading_frame_count_ratio =
254 waiting_animation_frame_count / loading_animation_frame_count; 270 waiting_animation_frame_count / loading_animation_frame_count;
255 271
256 initialized = true; 272 initialized = true;
257 } 273 }
258 } 274 }
259 275
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698