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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 1971463002: Get rid of some lingering MD-specific raster assets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix another test Created 4 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/browser_actions_container.h" 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 27 matching lines...) Expand all
38 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
39 #include "ui/gfx/geometry/rect.h" 39 #include "ui/gfx/geometry/rect.h"
40 #include "ui/resources/grit/ui_resources.h" 40 #include "ui/resources/grit/ui_resources.h"
41 #include "ui/views/bubble/bubble_dialog_delegate.h" 41 #include "ui/views/bubble/bubble_dialog_delegate.h"
42 #include "ui/views/controls/resize_area.h" 42 #include "ui/views/controls/resize_area.h"
43 #include "ui/views/painter.h" 43 #include "ui/views/painter.h"
44 #include "ui/views/widget/widget.h" 44 #include "ui/views/widget/widget.h"
45 45
46 namespace { 46 namespace {
47 47
48 // Horizontal spacing before the chevron (if visible).
49 // TODO(tdanderson): In material design, the chevron should have the same size
50 // and vertical spacing as the other action buttons.
51 int GetChevronSpacing() {
52 return GetLayoutConstant(TOOLBAR_STANDARD_SPACING) - 2;
53 }
54
55 // Returns the ToolbarView for the given |browser|. 48 // Returns the ToolbarView for the given |browser|.
56 ToolbarView* GetToolbarView(Browser* browser) { 49 ToolbarView* GetToolbarView(Browser* browser) {
57 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar(); 50 return BrowserView::GetBrowserViewForBrowser(browser)->toolbar();
58 } 51 }
59 52
60 } // namespace 53 } // namespace
61 54
62 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
63 // BrowserActionsContainer::DropPosition 56 // BrowserActionsContainer::DropPosition
64 57
(...skipping 19 matching lines...) Expand all
84 Browser* browser, 77 Browser* browser,
85 BrowserActionsContainer* main_container) 78 BrowserActionsContainer* main_container)
86 : toolbar_actions_bar_(new ToolbarActionsBar( 79 : toolbar_actions_bar_(new ToolbarActionsBar(
87 this, 80 this,
88 browser, 81 browser,
89 main_container ? 82 main_container ?
90 main_container->toolbar_actions_bar_.get() : nullptr)), 83 main_container->toolbar_actions_bar_.get() : nullptr)),
91 browser_(browser), 84 browser_(browser),
92 main_container_(main_container), 85 main_container_(main_container),
93 resize_area_(NULL), 86 resize_area_(NULL),
94 chevron_(NULL),
95 suppress_chevron_(false),
96 added_to_view_(false), 87 added_to_view_(false),
97 resize_starting_width_(-1), 88 resize_starting_width_(-1),
98 resize_amount_(0), 89 resize_amount_(0),
99 animation_target_size_(0), 90 animation_target_size_(0),
100 active_bubble_(nullptr) { 91 active_bubble_(nullptr) {
101 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); 92 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR);
102 93
103 bool overflow_experiment = 94 if (!ShownInsideMenu()) {
104 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled();
105 DCHECK(!in_overflow_mode() || overflow_experiment);
106
107 if (!in_overflow_mode()) {
108 resize_animation_.reset(new gfx::SlideAnimation(this)); 95 resize_animation_.reset(new gfx::SlideAnimation(this));
109 resize_area_ = new views::ResizeArea(this); 96 resize_area_ = new views::ResizeArea(this);
110 AddChildView(resize_area_); 97 AddChildView(resize_area_);
111
112 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside
113 // the Chrome menu.
114 if (!overflow_experiment) {
115 // Since the ChevronMenuButton holds a raw pointer to us, we need to
116 // ensure it doesn't outlive us. Having it owned by the view hierarchy as
117 // a child will suffice.
118 chevron_ = new ChevronMenuButton(this);
119 chevron_->EnableCanvasFlippingForRTLUI(true);
120 chevron_->SetAccessibleName(
121 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON));
122 chevron_->SetVisible(false);
123 AddChildView(chevron_);
124 }
125 } 98 }
126 } 99 }
127 100
128 BrowserActionsContainer::~BrowserActionsContainer() { 101 BrowserActionsContainer::~BrowserActionsContainer() {
129 if (active_bubble_) 102 if (active_bubble_)
130 active_bubble_->GetWidget()->Close(); 103 active_bubble_->GetWidget()->Close();
131 // We should synchronously receive the OnWidgetClosing() event, so we should 104 // We should synchronously receive the OnWidgetClosing() event, so we should
132 // always have cleared the active bubble by now. 105 // always have cleared the active bubble by now.
133 DCHECK(!active_bubble_); 106 DCHECK(!active_bubble_);
134 107
135 toolbar_actions_bar_->DeleteActions(); 108 toolbar_actions_bar_->DeleteActions();
136 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). 109 // All views should be removed as part of ToolbarActionsBar::DeleteActions().
137 DCHECK(toolbar_action_views_.empty()); 110 DCHECK(toolbar_action_views_.empty());
138 } 111 }
139 112
140 void BrowserActionsContainer::Init() {
141 LoadImages();
142 }
143
144 std::string BrowserActionsContainer::GetIdAt(size_t index) const { 113 std::string BrowserActionsContainer::GetIdAt(size_t index) const {
145 return toolbar_action_views_[index]->view_controller()->GetId(); 114 return toolbar_action_views_[index]->view_controller()->GetId();
146 } 115 }
147 116
148 ToolbarActionView* BrowserActionsContainer::GetViewForId( 117 ToolbarActionView* BrowserActionsContainer::GetViewForId(
149 const std::string& id) { 118 const std::string& id) {
150 for (ToolbarActionView* view : toolbar_action_views_) { 119 for (ToolbarActionView* view : toolbar_action_views_) {
151 if (view->view_controller()->GetId() == id) 120 if (view->view_controller()->GetId() == id)
152 return view; 121 return view;
153 } 122 }
(...skipping 14 matching lines...) Expand all
168 } 137 }
169 138
170 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { 139 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const {
171 if (!animating()) 140 if (!animating())
172 return VisibleBrowserActions(); 141 return VisibleBrowserActions();
173 142
174 return toolbar_actions_bar_->WidthToIconCount(animation_target_size_); 143 return toolbar_actions_bar_->WidthToIconCount(animation_target_size_);
175 } 144 }
176 145
177 bool BrowserActionsContainer::ShownInsideMenu() const { 146 bool BrowserActionsContainer::ShownInsideMenu() const {
178 return in_overflow_mode(); 147 return main_container_ != nullptr;
179 } 148 }
180 149
181 void BrowserActionsContainer::OnToolbarActionViewDragDone() { 150 void BrowserActionsContainer::OnToolbarActionViewDragDone() {
182 toolbar_actions_bar_->OnDragEnded(); 151 toolbar_actions_bar_->OnDragEnded();
183 } 152 }
184 153
185 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { 154 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() {
186 // With traditional overflow, the reference is the chevron. With the redesign, 155 return static_cast<views::MenuButton*>(
187 // we use the app menu instead. 156 GetToolbarView(browser_)->app_menu_button());
188 return chevron_ ? static_cast<views::MenuButton*>(chevron_)
189 : static_cast<views::MenuButton*>(
190 GetToolbarView(browser_)->app_menu_button());
191 } 157 }
192 158
193 void BrowserActionsContainer::AddViewForAction( 159 void BrowserActionsContainer::AddViewForAction(
194 ToolbarActionViewController* view_controller, 160 ToolbarActionViewController* view_controller,
195 size_t index) { 161 size_t index) {
196 if (chevron_)
197 chevron_->CloseMenu();
198
199 ToolbarActionView* view = new ToolbarActionView(view_controller, this); 162 ToolbarActionView* view = new ToolbarActionView(view_controller, this);
200 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); 163 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view);
201 AddChildViewAt(view, index); 164 AddChildViewAt(view, index);
202 } 165 }
203 166
204 void BrowserActionsContainer::RemoveViewForAction( 167 void BrowserActionsContainer::RemoveViewForAction(
205 ToolbarActionViewController* action) { 168 ToolbarActionViewController* action) {
206 if (chevron_)
207 chevron_->CloseMenu();
208
209 for (ToolbarActionViews::iterator iter = toolbar_action_views_.begin(); 169 for (ToolbarActionViews::iterator iter = toolbar_action_views_.begin();
210 iter != toolbar_action_views_.end(); ++iter) { 170 iter != toolbar_action_views_.end(); ++iter) {
211 if ((*iter)->view_controller() == action) { 171 if ((*iter)->view_controller() == action) {
212 delete *iter; 172 delete *iter;
213 toolbar_action_views_.erase(iter); 173 toolbar_action_views_.erase(iter);
214 break; 174 break;
215 } 175 }
216 } 176 }
217 } 177 }
218 178
(...skipping 27 matching lines...) Expand all
246 std::swap(toolbar_action_views_[i], toolbar_action_views_[j]); 206 std::swap(toolbar_action_views_[i], toolbar_action_views_[j]);
247 // Also move the view in the child views vector. 207 // Also move the view in the child views vector.
248 ReorderChildView(toolbar_action_views_[i], i); 208 ReorderChildView(toolbar_action_views_[i], i);
249 } 209 }
250 } 210 }
251 } 211 }
252 212
253 Layout(); 213 Layout();
254 } 214 }
255 215
256 void BrowserActionsContainer::ResizeAndAnimate( 216 void BrowserActionsContainer::ResizeAndAnimate(gfx::Tween::Type tween_type,
257 gfx::Tween::Type tween_type, 217 int target_width,
258 int target_width, 218 bool /*suppress_chevron*/) {
259 bool suppress_chevron) {
260 if (resize_animation_ && !toolbar_actions_bar_->suppress_animation()) { 219 if (resize_animation_ && !toolbar_actions_bar_->suppress_animation()) {
261 if (!in_overflow_mode()) { 220 if (!ShownInsideMenu()) {
262 // Make sure we don't try to animate to wider than the allowed width. 221 // Make sure we don't try to animate to wider than the allowed width.
263 int max_width = GetToolbarView(browser_)->GetMaxBrowserActionsWidth(); 222 int max_width = GetToolbarView(browser_)->GetMaxBrowserActionsWidth();
264 if (target_width > max_width) 223 if (target_width > max_width)
265 target_width = GetWidthForMaxWidth(max_width); 224 target_width = GetWidthForMaxWidth(max_width);
266 } 225 }
267 // Animate! We have to set the animation_target_size_ after calling Reset(), 226 // Animate! We have to set the animation_target_size_ after calling Reset(),
268 // because that could end up calling AnimationEnded which clears the value. 227 // because that could end up calling AnimationEnded which clears the value.
269 resize_animation_->Reset(); 228 resize_animation_->Reset();
270 resize_starting_width_ = width(); 229 resize_starting_width_ = width();
271 suppress_chevron_ = suppress_chevron;
272 resize_animation_->SetTweenType(tween_type); 230 resize_animation_->SetTweenType(tween_type);
273 animation_target_size_ = target_width; 231 animation_target_size_ = target_width;
274 resize_animation_->Show(); 232 resize_animation_->Show();
275 } else { 233 } else {
276 animation_target_size_ = target_width; 234 animation_target_size_ = target_width;
277 AnimationEnded(resize_animation_.get()); 235 AnimationEnded(resize_animation_.get());
278 } 236 }
279 } 237 }
280 238
281 void BrowserActionsContainer::SetChevronVisibility(bool visible) { 239 void BrowserActionsContainer::SetChevronVisibility(bool visible) {}
282 if (chevron_)
283 chevron_->SetVisible(visible);
284 }
285 240
286 int BrowserActionsContainer::GetWidth(GetWidthTime get_width_time) const { 241 int BrowserActionsContainer::GetWidth(GetWidthTime get_width_time) const {
287 return get_width_time == GET_WIDTH_AFTER_ANIMATION && 242 return get_width_time == GET_WIDTH_AFTER_ANIMATION &&
288 animation_target_size_ > 0 243 animation_target_size_ > 0
289 ? animation_target_size_ 244 ? animation_target_size_
290 : width(); 245 : width();
291 } 246 }
292 247
293 bool BrowserActionsContainer::IsAnimating() const { 248 bool BrowserActionsContainer::IsAnimating() const {
294 return animating(); 249 return animating();
295 } 250 }
296 251
297 void BrowserActionsContainer::StopAnimating() { 252 void BrowserActionsContainer::StopAnimating() {
298 animation_target_size_ = width(); 253 animation_target_size_ = width();
299 resize_animation_->Reset(); 254 resize_animation_->Reset();
300 } 255 }
301 256
302 int BrowserActionsContainer::GetChevronWidth() const { 257 int BrowserActionsContainer::GetChevronWidth() const {
303 return chevron_ ? 258 return 0;
304 chevron_->GetPreferredSize().width() + GetChevronSpacing() : 0;
305 } 259 }
306 260
307 void BrowserActionsContainer::ShowToolbarActionBubble( 261 void BrowserActionsContainer::ShowToolbarActionBubble(
308 std::unique_ptr<ToolbarActionsBarBubbleDelegate> controller) { 262 std::unique_ptr<ToolbarActionsBarBubbleDelegate> controller) {
309 // The container shouldn't be asked to show a bubble if it's animating. 263 // The container shouldn't be asked to show a bubble if it's animating.
310 DCHECK(!animating()); 264 DCHECK(!animating());
311 DCHECK(!active_bubble_); 265 DCHECK(!active_bubble_);
312 266
313 views::View* anchor_view = nullptr; 267 views::View* anchor_view = nullptr;
314 if (!controller->GetAnchorActionId().empty()) { 268 if (!controller->GetAnchorActionId().empty()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // show nothing). 303 // show nothing).
350 if (max_width < toolbar_actions_bar_->GetMinimumWidth()) 304 if (max_width < toolbar_actions_bar_->GetMinimumWidth())
351 return 0; 305 return 0;
352 preferred_width = toolbar_actions_bar_->IconCountToWidth( 306 preferred_width = toolbar_actions_bar_->IconCountToWidth(
353 toolbar_actions_bar_->WidthToIconCount(max_width)); 307 toolbar_actions_bar_->WidthToIconCount(max_width));
354 } 308 }
355 return preferred_width; 309 return preferred_width;
356 } 310 }
357 311
358 gfx::Size BrowserActionsContainer::GetPreferredSize() const { 312 gfx::Size BrowserActionsContainer::GetPreferredSize() const {
359 if (in_overflow_mode()) 313 if (ShownInsideMenu())
360 return toolbar_actions_bar_->GetPreferredSize(); 314 return toolbar_actions_bar_->GetPreferredSize();
361 315
362 // If there are no actions to show, then don't show the container at all. 316 // If there are no actions to show, then don't show the container at all.
363 if (toolbar_action_views_.empty()) 317 if (toolbar_action_views_.empty())
364 return gfx::Size(); 318 return gfx::Size();
365 319
366 // When resizing, preferred width is the starting width - resize amount. 320 // When resizing, preferred width is the starting width - resize amount.
367 // Otherwise, use the normal preferred width. 321 // Otherwise, use the normal preferred width.
368 int preferred_width = resize_starting_width_ == -1 ? 322 int preferred_width = resize_starting_width_ == -1 ?
369 toolbar_actions_bar_->GetPreferredSize().width() : 323 toolbar_actions_bar_->GetPreferredSize().width() :
370 resize_starting_width_ - resize_amount_; 324 resize_starting_width_ - resize_amount_;
371 // In either case, clamp it within the max/min bounds. 325 // In either case, clamp it within the max/min bounds.
372 preferred_width = std::min( 326 preferred_width = std::min(
373 std::max(toolbar_actions_bar_->GetMinimumWidth(), preferred_width), 327 std::max(toolbar_actions_bar_->GetMinimumWidth(), preferred_width),
374 toolbar_actions_bar_->GetMaximumWidth()); 328 toolbar_actions_bar_->GetMaximumWidth());
375 return gfx::Size(preferred_width, ToolbarActionsBar::IconHeight()); 329 return gfx::Size(preferred_width, ToolbarActionsBar::IconHeight());
376 } 330 }
377 331
378 int BrowserActionsContainer::GetHeightForWidth(int width) const { 332 int BrowserActionsContainer::GetHeightForWidth(int width) const {
379 if (in_overflow_mode()) 333 if (ShownInsideMenu())
380 toolbar_actions_bar_->SetOverflowRowWidth(width); 334 toolbar_actions_bar_->SetOverflowRowWidth(width);
381 return GetPreferredSize().height(); 335 return GetPreferredSize().height();
382 } 336 }
383 337
384 gfx::Size BrowserActionsContainer::GetMinimumSize() const { 338 gfx::Size BrowserActionsContainer::GetMinimumSize() const {
385 return gfx::Size(toolbar_actions_bar_->GetMinimumWidth(), 339 return gfx::Size(toolbar_actions_bar_->GetMinimumWidth(),
386 ToolbarActionsBar::IconHeight()); 340 ToolbarActionsBar::IconHeight());
387 } 341 }
388 342
389 void BrowserActionsContainer::Layout() { 343 void BrowserActionsContainer::Layout() {
390 if (toolbar_actions_bar_->suppress_layout()) 344 if (toolbar_actions_bar_->suppress_layout())
391 return; 345 return;
392 346
393 if (toolbar_action_views_.empty()) { 347 if (toolbar_action_views_.empty()) {
394 SetVisible(false); 348 SetVisible(false);
395 return; 349 return;
396 } 350 }
397 351
398 SetVisible(true); 352 SetVisible(true);
399 if (resize_area_) 353 if (resize_area_)
400 resize_area_->SetBounds(0, 0, platform_settings().item_spacing, height()); 354 resize_area_->SetBounds(0, 0, platform_settings().item_spacing, height());
401 355
402 // The range of visible icons, from start_index (inclusive) to end_index 356 // The range of visible icons, from start_index (inclusive) to end_index
403 // (exclusive). 357 // (exclusive).
404 size_t start_index = toolbar_actions_bar_->GetStartIndexInBounds(); 358 size_t start_index = toolbar_actions_bar_->GetStartIndexInBounds();
405 size_t end_index = toolbar_actions_bar_->GetEndIndexInBounds(); 359 size_t end_index = toolbar_actions_bar_->GetEndIndexInBounds();
406 360
407 // If the icons don't all fit, show the chevron (unless suppressed).
408 if (chevron_ && !suppress_chevron_ && toolbar_actions_bar_->NeedsOverflow()) {
409 chevron_->SetVisible(true);
410 gfx::Size chevron_size(chevron_->GetPreferredSize());
411 chevron_->SetBounds(
412 width() - GetLayoutConstant(TOOLBAR_STANDARD_SPACING) -
413 chevron_size.width(),
414 0,
415 chevron_size.width(),
416 chevron_size.height());
417 } else if (chevron_) {
418 chevron_->SetVisible(false);
419 }
420
421 // Now draw the icons for the actions in the available space. Once all the 361 // Now draw the icons for the actions in the available space. Once all the
422 // variables are in place, the layout works equally well for the main and 362 // variables are in place, the layout works equally well for the main and
423 // overflow container. 363 // overflow container.
424 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { 364 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) {
425 ToolbarActionView* view = toolbar_action_views_[i]; 365 ToolbarActionView* view = toolbar_action_views_[i];
426 if (i < start_index || i >= end_index) { 366 if (i < start_index || i >= end_index) {
427 view->SetVisible(false); 367 view->SetVisible(false);
428 } else { 368 } else {
429 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i)); 369 view->SetBoundsRect(toolbar_actions_bar_->GetFrameForIndex(i));
430 view->SetVisible(true); 370 view->SetVisible(true);
(...skipping 30 matching lines...) Expand all
461 int offset_into_icon_area = 401 int offset_into_icon_area =
462 GetMirroredXInView(event.x()) - 402 GetMirroredXInView(event.x()) -
463 GetLayoutConstant(TOOLBAR_STANDARD_SPACING); 403 GetLayoutConstant(TOOLBAR_STANDARD_SPACING);
464 404
465 // Next, figure out what row we're on. This only matters for overflow mode, 405 // Next, figure out what row we're on. This only matters for overflow mode,
466 // but the calculation is the same for both. 406 // but the calculation is the same for both.
467 row_index = event.y() / ToolbarActionsBar::IconHeight(); 407 row_index = event.y() / ToolbarActionsBar::IconHeight();
468 408
469 // Sanity check - we should never be on a different row in the main 409 // Sanity check - we should never be on a different row in the main
470 // container. 410 // container.
471 DCHECK(in_overflow_mode() || row_index == 0); 411 DCHECK(ShownInsideMenu() || row_index == 0);
472 412
473 // Next, we determine which icon to place the indicator in front of. We want 413 // Next, we determine which icon to place the indicator in front of. We want
474 // to place the indicator in front of icon n when the cursor is between the 414 // to place the indicator in front of icon n when the cursor is between the
475 // midpoints of icons (n - 1) and n. To do this we take the offset into the 415 // midpoints of icons (n - 1) and n. To do this we take the offset into the
476 // icon area and transform it as follows: 416 // icon area and transform it as follows:
477 // 417 //
478 // Real icon area: 418 // Real icon area:
479 // 0 a * b c 419 // 0 a * b c
480 // | | | | 420 // | | | |
481 // |[IC|ON] [IC|ON] [IC|ON] 421 // |[IC|ON] [IC|ON] [IC|ON]
482 // We want to be before icon 0 for 0 < x <= a, icon 1 for a < x <= b, etc. 422 // We want to be before icon 0 for 0 < x <= a, icon 1 for a < x <= b, etc.
483 // Here the "*" represents the offset into the icon area, and since it's 423 // Here the "*" represents the offset into the icon area, and since it's
484 // between a and b, we want to return "1". 424 // between a and b, we want to return "1".
485 // 425 //
486 // Transformed "icon area": 426 // Transformed "icon area":
487 // 0 a * b c 427 // 0 a * b c
488 // | | | | 428 // | | | |
489 // |[ICON] |[ICON] |[ICON] | 429 // |[ICON] |[ICON] |[ICON] |
490 // If we shift both our offset and our divider points later by half an icon 430 // If we shift both our offset and our divider points later by half an icon
491 // plus one spacing unit, then it becomes very easy to calculate how many 431 // plus one spacing unit, then it becomes very easy to calculate how many
492 // divider points we've passed, because they're the multiples of "one icon 432 // divider points we've passed, because they're the multiples of "one icon
493 // plus padding". 433 // plus padding".
494 int before_icon_unclamped = 434 int before_icon_unclamped =
495 (offset_into_icon_area + (ToolbarActionsBar::IconWidth(false) / 2) + 435 (offset_into_icon_area + (ToolbarActionsBar::IconWidth(false) / 2) +
496 platform_settings().item_spacing) / ToolbarActionsBar::IconWidth(true); 436 platform_settings().item_spacing) / ToolbarActionsBar::IconWidth(true);
497 437
498 // We need to figure out how many icons are visible on the relevant row. 438 // We need to figure out how many icons are visible on the relevant row.
499 // In the main container, this will just be the visible actions. 439 // In the main container, this will just be the visible actions.
500 int visible_icons_on_row = VisibleBrowserActionsAfterAnimation(); 440 int visible_icons_on_row = VisibleBrowserActionsAfterAnimation();
501 if (in_overflow_mode()) { 441 if (ShownInsideMenu()) {
502 int icons_per_row = platform_settings().icons_per_overflow_menu_row; 442 int icons_per_row = platform_settings().icons_per_overflow_menu_row;
503 // If this is the final row of the overflow, then this is the remainder of 443 // If this is the final row of the overflow, then this is the remainder of
504 // visible icons. Otherwise, it's a full row (kIconsPerRow). 444 // visible icons. Otherwise, it's a full row (kIconsPerRow).
505 visible_icons_on_row = 445 visible_icons_on_row =
506 row_index == 446 row_index ==
507 static_cast<size_t>(visible_icons_on_row / icons_per_row) ? 447 static_cast<size_t>(visible_icons_on_row / icons_per_row) ?
508 visible_icons_on_row % icons_per_row : icons_per_row; 448 visible_icons_on_row % icons_per_row : icons_per_row;
509 } 449 }
510 450
511 // Because the user can drag outside the container bounds, we need to clamp 451 // Because the user can drag outside the container bounds, we need to clamp
(...skipping 24 matching lines...) Expand all
536 BrowserActionDragData data; 476 BrowserActionDragData data;
537 if (!data.Read(event.data())) 477 if (!data.Read(event.data()))
538 return ui::DragDropTypes::DRAG_NONE; 478 return ui::DragDropTypes::DRAG_NONE;
539 479
540 // Make sure we have the same view as we started with. 480 // Make sure we have the same view as we started with.
541 DCHECK_EQ(GetIdAt(data.index()), data.id()); 481 DCHECK_EQ(GetIdAt(data.index()), data.id());
542 482
543 size_t i = drop_position_->row * 483 size_t i = drop_position_->row *
544 platform_settings().icons_per_overflow_menu_row + 484 platform_settings().icons_per_overflow_menu_row +
545 drop_position_->icon_in_row; 485 drop_position_->icon_in_row;
546 if (in_overflow_mode()) 486 if (ShownInsideMenu())
547 i += main_container_->VisibleBrowserActionsAfterAnimation(); 487 i += main_container_->VisibleBrowserActionsAfterAnimation();
548 // |i| now points to the item to the right of the drop indicator*, which is 488 // |i| now points to the item to the right of the drop indicator*, which is
549 // correct when dragging an icon to the left. When dragging to the right, 489 // correct when dragging an icon to the left. When dragging to the right,
550 // however, we want the icon being dragged to get the index of the item to 490 // however, we want the icon being dragged to get the index of the item to
551 // the left of the drop indicator, so we subtract one. 491 // the left of the drop indicator, so we subtract one.
552 // * Well, it can also point to the end, but not when dragging to the left. :) 492 // * Well, it can also point to the end, but not when dragging to the left. :)
553 if (i > data.index()) 493 if (i > data.index())
554 --i; 494 --i;
555 495
556 ToolbarActionsBar::DragType drag_type = ToolbarActionsBar::DRAG_TO_SAME; 496 ToolbarActionsBar::DragType drag_type = ToolbarActionsBar::DRAG_TO_SAME;
557 if (!toolbar_action_views_[data.index()]->visible()) 497 if (!toolbar_action_views_[data.index()]->visible())
558 drag_type = in_overflow_mode() ? ToolbarActionsBar::DRAG_TO_OVERFLOW : 498 drag_type = ShownInsideMenu() ? ToolbarActionsBar::DRAG_TO_OVERFLOW :
559 ToolbarActionsBar::DRAG_TO_MAIN; 499 ToolbarActionsBar::DRAG_TO_MAIN;
560 500
561 toolbar_actions_bar_->OnDragDrop(data.index(), i, drag_type); 501 toolbar_actions_bar_->OnDragDrop(data.index(), i, drag_type);
562 502
563 OnDragExited(); // Perform clean up after dragging. 503 OnDragExited(); // Perform clean up after dragging.
564 return ui::DragDropTypes::DRAG_MOVE; 504 return ui::DragDropTypes::DRAG_MOVE;
565 } 505 }
566 506
567 void BrowserActionsContainer::GetAccessibleState( 507 void BrowserActionsContainer::GetAccessibleState(
568 ui::AXViewState* state) { 508 ui::AXViewState* state) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 585
646 void BrowserActionsContainer::AnimationCanceled( 586 void BrowserActionsContainer::AnimationCanceled(
647 const gfx::Animation* animation) { 587 const gfx::Animation* animation) {
648 AnimationEnded(animation); 588 AnimationEnded(animation);
649 } 589 }
650 590
651 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { 591 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) {
652 animation_target_size_ = 0; 592 animation_target_size_ = 0;
653 resize_amount_ = 0; 593 resize_amount_ = 0;
654 resize_starting_width_ = -1; 594 resize_starting_width_ = -1;
655 suppress_chevron_ = false;
656 parent()->Layout(); 595 parent()->Layout();
657 596
658 toolbar_actions_bar_->OnAnimationEnded(); 597 toolbar_actions_bar_->OnAnimationEnded();
659 } 598 }
660 599
661 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { 600 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() {
662 return browser_->tab_strip_model()->GetActiveWebContents(); 601 return browser_->tab_strip_model()->GetActiveWebContents();
663 } 602 }
664 603
665 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { 604 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) {
666 // If the views haven't been initialized yet, wait for the next call to 605 // If the views haven't been initialized yet, wait for the next call to
667 // paint (one will be triggered by entering highlight mode). 606 // paint (one will be triggered by entering highlight mode).
668 if (toolbar_actions_bar_->is_highlighting() && 607 if (toolbar_actions_bar_->is_highlighting() &&
669 !toolbar_action_views_.empty() && !in_overflow_mode()) { 608 !toolbar_action_views_.empty() && !ShownInsideMenu()) {
670 ToolbarActionsModel::HighlightType highlight_type = 609 ToolbarActionsModel::HighlightType highlight_type =
671 toolbar_actions_bar_->highlight_type(); 610 toolbar_actions_bar_->highlight_type();
672 views::Painter* painter = 611 views::Painter* painter =
673 highlight_type == ToolbarActionsModel::HIGHLIGHT_INFO 612 highlight_type == ToolbarActionsModel::HIGHLIGHT_INFO
674 ? info_highlight_painter_.get() 613 ? info_highlight_painter_.get()
675 : warning_highlight_painter_.get(); 614 : warning_highlight_painter_.get();
676 views::Painter::PaintPainterAt(canvas, painter, GetLocalBounds()); 615 views::Painter::PaintPainterAt(canvas, painter, GetLocalBounds());
677 } 616 }
678 617
679 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while 618 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while
(...skipping 23 matching lines...) Expand all
703 kDropIndicatorWidth, 642 kDropIndicatorWidth,
704 row_height); 643 row_height);
705 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds)); 644 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds));
706 645
707 // Color of the drop indicator. 646 // Color of the drop indicator.
708 static const SkColor kDropIndicatorColor = SK_ColorBLACK; 647 static const SkColor kDropIndicatorColor = SK_ColorBLACK;
709 canvas->FillRect(indicator_bounds, kDropIndicatorColor); 648 canvas->FillRect(indicator_bounds, kDropIndicatorColor);
710 } 649 }
711 } 650 }
712 651
713 void BrowserActionsContainer::OnThemeChanged() {
714 LoadImages();
715 }
716
717 void BrowserActionsContainer::ViewHierarchyChanged( 652 void BrowserActionsContainer::ViewHierarchyChanged(
718 const ViewHierarchyChangedDetails& details) { 653 const ViewHierarchyChangedDetails& details) {
719 if (!toolbar_actions_bar_->enabled()) 654 if (!toolbar_actions_bar_->enabled())
720 return; 655 return;
721 656
722 if (details.is_add && details.child == this) { 657 if (details.is_add && details.child == this) {
723 // Initial toolbar button creation and placement in the widget hierarchy. 658 // Initial toolbar button creation and placement in the widget hierarchy.
724 // We do this here instead of in the constructor because adding views 659 // We do this here instead of in the constructor because adding views
725 // calls Layout on the Toolbar, which needs this object to be constructed 660 // calls Layout on the Toolbar, which needs this object to be constructed
726 // before its Layout function is called. 661 // before its Layout function is called.
727 toolbar_actions_bar_->CreateActions(); 662 toolbar_actions_bar_->CreateActions();
728 663
729 added_to_view_ = true; 664 added_to_view_ = true;
730 } 665 }
731 } 666 }
732 667
733 void BrowserActionsContainer::LoadImages() {
734 if (in_overflow_mode())
735 return; // Overflow mode has neither a chevron nor highlighting.
736
737 const ui::ThemeProvider* tp = GetThemeProvider();
738 if (tp && chevron_) {
739 chevron_->SetImage(views::Button::STATE_NORMAL,
740 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW));
741 }
742
743 const int kInfoImages[] = IMAGE_GRID(IDR_TOOLBAR_ACTION_HIGHLIGHT);
744 info_highlight_painter_.reset(
745 views::Painter::CreateImageGridPainter(kInfoImages));
746 const int kWarningImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT);
747 warning_highlight_painter_.reset(
748 views::Painter::CreateImageGridPainter(kWarningImages));
749 }
750
751 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { 668 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) {
752 DCHECK(active_bubble_); 669 DCHECK(active_bubble_);
753 DCHECK_EQ(active_bubble_->GetWidget(), widget); 670 DCHECK_EQ(active_bubble_->GetWidget(), widget);
754 widget->RemoveObserver(this); 671 widget->RemoveObserver(this);
755 active_bubble_ = nullptr; 672 active_bubble_ = nullptr;
756 toolbar_actions_bar_->OnBubbleClosed(); 673 toolbar_actions_bar_->OnBubbleClosed();
757 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698