OLD | NEW |
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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 | 158 |
159 BrowserActionsContainer::~BrowserActionsContainer() { | 159 BrowserActionsContainer::~BrowserActionsContainer() { |
160 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 160 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
161 observers_, | 161 observers_, |
162 OnBrowserActionsContainerDestroyed()); | 162 OnBrowserActionsContainerDestroyed()); |
163 | 163 |
164 if (model_) | 164 if (model_) |
165 model_->RemoveObserver(this); | 165 model_->RemoveObserver(this); |
166 HideActivePopup(); | 166 HideActivePopup(); |
167 DeleteBrowserActionViews(); | 167 DeleteToolbarActionViews(); |
168 } | 168 } |
169 | 169 |
170 void BrowserActionsContainer::Init() { | 170 void BrowserActionsContainer::Init() { |
171 LoadImages(); | 171 LoadImages(); |
172 | 172 |
173 // We wait to set the container width until now so that the chevron images | 173 // We wait to set the container width until now so that the chevron images |
174 // will be loaded. The width calculation needs to know the chevron size. | 174 // will be loaded. The width calculation needs to know the chevron size. |
175 if (model_ && model_->extensions_initialized()) { | 175 if (model_ && model_->extensions_initialized()) { |
176 container_width_ = GetPreferredWidth(); | 176 container_width_ = GetPreferredWidth(); |
177 SetChevronVisibility(); | 177 SetChevronVisibility(); |
178 } | 178 } |
179 | 179 |
180 initialized_ = true; | 180 initialized_ = true; |
181 } | 181 } |
182 | 182 |
183 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { | 183 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { |
184 return browser_action_views_[index]->view_controller()->GetId(); | 184 return toolbar_action_views_[index]->view_controller()->GetId(); |
185 } | 185 } |
186 | 186 |
187 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 187 ToolbarActionView* BrowserActionsContainer::GetViewForExtension( |
188 const Extension* extension) { | 188 const Extension* extension) { |
189 for (BrowserActionView* view : browser_action_views_) { | 189 for (ToolbarActionView* view : toolbar_action_views_) { |
190 if (view->view_controller()->GetId() == extension->id()) | 190 if (view->view_controller()->GetId() == extension->id()) |
191 return view; | 191 return view; |
192 } | 192 } |
193 return NULL; | 193 return nullptr; |
194 } | 194 } |
195 | 195 |
196 void BrowserActionsContainer::RefreshBrowserActionViews() { | 196 void BrowserActionsContainer::RefreshToolbarActionViews() { |
197 for (BrowserActionView* view : browser_action_views_) | 197 for (ToolbarActionView* view : toolbar_action_views_) |
198 view->UpdateState(); | 198 view->UpdateState(); |
199 } | 199 } |
200 | 200 |
201 void BrowserActionsContainer::CreateBrowserActionViews() { | 201 void BrowserActionsContainer::CreateToolbarActionViews() { |
202 DCHECK(browser_action_views_.empty()); | 202 DCHECK(toolbar_action_views_.empty()); |
203 if (!model_) | 203 if (!model_) |
204 return; | 204 return; |
205 | 205 |
206 ScopedVector<ToolbarActionViewController> actions = | 206 ScopedVector<ToolbarActionViewController> actions = |
207 GetToolbarActions(model_, browser_); | 207 GetToolbarActions(model_, browser_); |
208 for (ToolbarActionViewController* controller : actions) { | 208 for (ToolbarActionViewController* controller : actions) { |
209 BrowserActionView* view = | 209 ToolbarActionView* view = |
210 new BrowserActionView(make_scoped_ptr(controller), browser_, this); | 210 new ToolbarActionView(make_scoped_ptr(controller), browser_, this); |
211 browser_action_views_.push_back(view); | 211 toolbar_action_views_.push_back(view); |
212 AddChildView(view); | 212 AddChildView(view); |
213 } | 213 } |
214 actions.weak_clear(); | 214 actions.weak_clear(); |
215 } | 215 } |
216 | 216 |
217 void BrowserActionsContainer::DeleteBrowserActionViews() { | 217 void BrowserActionsContainer::DeleteToolbarActionViews() { |
218 HideActivePopup(); | 218 HideActivePopup(); |
219 STLDeleteElements(&browser_action_views_); | 219 STLDeleteElements(&toolbar_action_views_); |
220 } | 220 } |
221 | 221 |
222 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 222 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
223 size_t visible_actions = 0; | 223 size_t visible_actions = 0; |
224 for (const BrowserActionView* view : browser_action_views_) { | 224 for (const ToolbarActionView* view : toolbar_action_views_) { |
225 if (view->visible()) | 225 if (view->visible()) |
226 ++visible_actions; | 226 ++visible_actions; |
227 } | 227 } |
228 return visible_actions; | 228 return visible_actions; |
229 } | 229 } |
230 | 230 |
231 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { | 231 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { |
232 if (!animating()) | 232 if (!animating()) |
233 return VisibleBrowserActions(); | 233 return VisibleBrowserActions(); |
234 | 234 |
(...skipping 11 matching lines...) Expand all Loading... |
246 } | 246 } |
247 | 247 |
248 void BrowserActionsContainer::NotifyActionMovedToOverflow() { | 248 void BrowserActionsContainer::NotifyActionMovedToOverflow() { |
249 // When an action is moved to overflow, we shrink the size of the container | 249 // When an action is moved to overflow, we shrink the size of the container |
250 // by 1. | 250 // by 1. |
251 int icon_count = model_->GetVisibleIconCount(); | 251 int icon_count = model_->GetVisibleIconCount(); |
252 // Since this happens when an icon moves from the main bar to overflow, we | 252 // Since this happens when an icon moves from the main bar to overflow, we |
253 // can't possibly have had no visible icons on the main bar. | 253 // can't possibly have had no visible icons on the main bar. |
254 DCHECK_NE(0, icon_count); | 254 DCHECK_NE(0, icon_count); |
255 if (icon_count == -1) | 255 if (icon_count == -1) |
256 icon_count = browser_action_views_.size(); | 256 icon_count = toolbar_action_views_.size(); |
257 model_->SetVisibleIconCount(icon_count - 1); | 257 model_->SetVisibleIconCount(icon_count - 1); |
258 } | 258 } |
259 | 259 |
260 bool BrowserActionsContainer::ShownInsideMenu() const { | 260 bool BrowserActionsContainer::ShownInsideMenu() const { |
261 return in_overflow_mode(); | 261 return in_overflow_mode(); |
262 } | 262 } |
263 | 263 |
264 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 264 void BrowserActionsContainer::OnToolbarActionViewDragDone() { |
265 ToolbarVisibleCountChanged(); | 265 ToolbarVisibleCountChanged(); |
266 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 266 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
267 observers_, | 267 observers_, |
268 OnBrowserActionDragDone()); | 268 OnBrowserActionDragDone()); |
269 } | 269 } |
270 | 270 |
271 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 271 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
272 // With traditional overflow, the reference is the chevron. With the | 272 // With traditional overflow, the reference is the chevron. With the |
273 // redesign, we use the wrench menu instead. | 273 // redesign, we use the wrench menu instead. |
274 return chevron_ ? | 274 return chevron_ ? |
275 chevron_ : | 275 chevron_ : |
276 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); | 276 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); |
277 } | 277 } |
278 | 278 |
279 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) { | 279 void BrowserActionsContainer::SetPopupOwner(ToolbarActionView* popup_owner) { |
280 // We should never be setting a popup owner when one already exists, and | 280 // We should never be setting a popup owner when one already exists, and |
281 // never unsetting one when one wasn't set. | 281 // never unsetting one when one wasn't set. |
282 DCHECK((!popup_owner_ && popup_owner) || | 282 DCHECK((!popup_owner_ && popup_owner) || |
283 (popup_owner_ && !popup_owner)); | 283 (popup_owner_ && !popup_owner)); |
284 popup_owner_ = popup_owner; | 284 popup_owner_ = popup_owner; |
285 } | 285 } |
286 | 286 |
287 void BrowserActionsContainer::HideActivePopup() { | 287 void BrowserActionsContainer::HideActivePopup() { |
288 if (popup_owner_) | 288 if (popup_owner_) |
289 popup_owner_->view_controller()->HidePopup(); | 289 popup_owner_->view_controller()->HidePopup(); |
290 } | 290 } |
291 | 291 |
292 BrowserActionView* BrowserActionsContainer::GetMainViewForAction( | 292 ToolbarActionView* BrowserActionsContainer::GetMainViewForAction( |
293 BrowserActionView* view) { | 293 ToolbarActionView* view) { |
294 if (!in_overflow_mode()) | 294 if (!in_overflow_mode()) |
295 return view; // This is the main view. | 295 return view; // This is the main view. |
296 | 296 |
297 // The overflow container and main container each have the same views and | 297 // The overflow container and main container each have the same views and |
298 // view indices, so we can return the view of the index that |view| has in | 298 // view indices, so we can return the view of the index that |view| has in |
299 // this container. | 299 // this container. |
300 BrowserActionViews::const_iterator iter = | 300 ToolbarActionViews::const_iterator iter = |
301 std::find(browser_action_views_.begin(), | 301 std::find(toolbar_action_views_.begin(), |
302 browser_action_views_.end(), | 302 toolbar_action_views_.end(), |
303 view); | 303 view); |
304 DCHECK(iter != browser_action_views_.end()); | 304 DCHECK(iter != toolbar_action_views_.end()); |
305 size_t index = iter - browser_action_views_.begin(); | 305 size_t index = iter - toolbar_action_views_.begin(); |
306 return main_container_->browser_action_views_[index]; | 306 return main_container_->toolbar_action_views_[index]; |
307 } | 307 } |
308 | 308 |
309 void BrowserActionsContainer::AddObserver( | 309 void BrowserActionsContainer::AddObserver( |
310 BrowserActionsContainerObserver* observer) { | 310 BrowserActionsContainerObserver* observer) { |
311 observers_.AddObserver(observer); | 311 observers_.AddObserver(observer); |
312 } | 312 } |
313 | 313 |
314 void BrowserActionsContainer::RemoveObserver( | 314 void BrowserActionsContainer::RemoveObserver( |
315 BrowserActionsContainerObserver* observer) { | 315 BrowserActionsContainerObserver* observer) { |
316 observers_.RemoveObserver(observer); | 316 observers_.RemoveObserver(observer); |
317 } | 317 } |
318 | 318 |
319 gfx::Size BrowserActionsContainer::GetPreferredSize() const { | 319 gfx::Size BrowserActionsContainer::GetPreferredSize() const { |
320 if (in_overflow_mode()) { | 320 if (in_overflow_mode()) { |
321 int icon_count = GetIconCount(); | 321 int icon_count = GetIconCount(); |
322 // In overflow, we always have a preferred size of a full row (even if we | 322 // In overflow, we always have a preferred size of a full row (even if we |
323 // don't use it), and always of at least one row. The parent may decide to | 323 // don't use it), and always of at least one row. The parent may decide to |
324 // show us even when empty, e.g. as a drag target for dragging in icons from | 324 // show us even when empty, e.g. as a drag target for dragging in icons from |
325 // the main container. | 325 // the main container. |
326 int row_count = | 326 int row_count = |
327 ((std::max(0, icon_count - 1)) / icons_per_overflow_menu_row_) + 1; | 327 ((std::max(0, icon_count - 1)) / icons_per_overflow_menu_row_) + 1; |
328 return gfx::Size(IconCountToWidth(icons_per_overflow_menu_row_), | 328 return gfx::Size(IconCountToWidth(icons_per_overflow_menu_row_), |
329 row_count * IconHeight()); | 329 row_count * IconHeight()); |
330 } | 330 } |
331 | 331 |
332 // If there are no actions to show, then don't show the container at all. | 332 // If there are no actions to show, then don't show the container at all. |
333 if (browser_action_views_.empty()) | 333 if (toolbar_action_views_.empty()) |
334 return gfx::Size(); | 334 return gfx::Size(); |
335 | 335 |
336 // We calculate the size of the view by taking the current width and | 336 // We calculate the size of the view by taking the current width and |
337 // subtracting resize_amount_ (the latter represents how far the user is | 337 // subtracting resize_amount_ (the latter represents how far the user is |
338 // resizing the view or, if animating the snapping, how far to animate it). | 338 // resizing the view or, if animating the snapping, how far to animate it). |
339 // But we also clamp it to a minimum size and the maximum size, so that the | 339 // But we also clamp it to a minimum size and the maximum size, so that the |
340 // container can never shrink too far or take up more space than it needs. | 340 // container can never shrink too far or take up more space than it needs. |
341 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). | 341 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). |
342 int preferred_width = std::min( | 342 int preferred_width = std::min( |
343 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), | 343 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), |
344 IconCountToWidth(-1)); | 344 IconCountToWidth(-1)); |
345 return gfx::Size(preferred_width, IconHeight()); | 345 return gfx::Size(preferred_width, IconHeight()); |
346 } | 346 } |
347 | 347 |
348 int BrowserActionsContainer::GetHeightForWidth(int width) const { | 348 int BrowserActionsContainer::GetHeightForWidth(int width) const { |
349 if (in_overflow_mode()) | 349 if (in_overflow_mode()) |
350 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); | 350 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); |
351 return GetPreferredSize().height(); | 351 return GetPreferredSize().height(); |
352 } | 352 } |
353 | 353 |
354 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 354 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
355 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); | 355 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); |
356 return gfx::Size(min_width, IconHeight()); | 356 return gfx::Size(min_width, IconHeight()); |
357 } | 357 } |
358 | 358 |
359 void BrowserActionsContainer::Layout() { | 359 void BrowserActionsContainer::Layout() { |
360 if (browser_action_views_.empty()) { | 360 if (toolbar_action_views_.empty()) { |
361 SetVisible(false); | 361 SetVisible(false); |
362 return; | 362 return; |
363 } | 363 } |
364 | 364 |
365 SetVisible(true); | 365 SetVisible(true); |
366 if (resize_area_) | 366 if (resize_area_) |
367 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 367 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
368 | 368 |
369 // If the icons don't all fit, show the chevron (unless suppressed). | 369 // If the icons don't all fit, show the chevron (unless suppressed). |
370 int max_x = GetPreferredSize().width(); | 370 int max_x = GetPreferredSize().width(); |
(...skipping 14 matching lines...) Expand all Loading... |
385 int container_padding = | 385 int container_padding = |
386 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing; | 386 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing; |
387 // The range of visible icons, from start_index (inclusive) to end_index | 387 // The range of visible icons, from start_index (inclusive) to end_index |
388 // (exclusive). | 388 // (exclusive). |
389 size_t start_index = in_overflow_mode() ? | 389 size_t start_index = in_overflow_mode() ? |
390 main_container_->VisibleBrowserActionsAfterAnimation() : 0u; | 390 main_container_->VisibleBrowserActionsAfterAnimation() : 0u; |
391 // For the main container's last visible icon, we calculate how many icons we | 391 // For the main container's last visible icon, we calculate how many icons we |
392 // can display with the given width. We add an extra kItemSpacing because the | 392 // can display with the given width. We add an extra kItemSpacing because the |
393 // last icon doesn't need padding, but we want it to divide easily. | 393 // last icon doesn't need padding, but we want it to divide easily. |
394 size_t end_index = in_overflow_mode() ? | 394 size_t end_index = in_overflow_mode() ? |
395 browser_action_views_.size() : | 395 toolbar_action_views_.size() : |
396 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true); | 396 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true); |
397 // The maximum length for one row of icons. | 397 // The maximum length for one row of icons. |
398 size_t row_length = | 398 size_t row_length = |
399 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index; | 399 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index; |
400 | 400 |
401 // Now draw the icons for the browser actions in the available space. Once | 401 // Now draw the icons for the actions in the available space. Once all the |
402 // all the variables are in place, the layout works equally well for the main | 402 // variables are in place, the layout works equally well for the main and |
403 // and overflow container. | 403 // overflow container. |
404 for (size_t i = 0u; i < browser_action_views_.size(); ++i) { | 404 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { |
405 BrowserActionView* view = browser_action_views_[i]; | 405 ToolbarActionView* view = toolbar_action_views_[i]; |
406 if (i < start_index || i >= end_index) { | 406 if (i < start_index || i >= end_index) { |
407 view->SetVisible(false); | 407 view->SetVisible(false); |
408 } else { | 408 } else { |
409 size_t relative_index = i - start_index; | 409 size_t relative_index = i - start_index; |
410 size_t index_in_row = relative_index % row_length; | 410 size_t index_in_row = relative_index % row_length; |
411 size_t row_index = relative_index / row_length; | 411 size_t row_index = relative_index / row_length; |
412 view->SetBounds(container_padding + index_in_row * IconWidth(true), | 412 view->SetBounds(container_padding + index_in_row * IconWidth(true), |
413 row_index * IconHeight(), | 413 row_index * IconHeight(), |
414 IconWidth(false), | 414 IconWidth(false), |
415 IconHeight()); | 415 IconHeight()); |
(...skipping 13 matching lines...) Expand all Loading... |
429 } | 429 } |
430 | 430 |
431 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 431 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
432 return BrowserActionDragData::CanDrop(data, profile_); | 432 return BrowserActionDragData::CanDrop(data, profile_); |
433 } | 433 } |
434 | 434 |
435 int BrowserActionsContainer::OnDragUpdated( | 435 int BrowserActionsContainer::OnDragUpdated( |
436 const ui::DropTargetEvent& event) { | 436 const ui::DropTargetEvent& event) { |
437 size_t row_index = 0; | 437 size_t row_index = 0; |
438 size_t before_icon_in_row = 0; | 438 size_t before_icon_in_row = 0; |
439 // If there are no visible browser actions (such as when dragging an icon to | 439 // If there are no visible actions (such as when dragging an icon to an empty |
440 // an empty overflow/main container), then 0, 0 for row, column is correct. | 440 // overflow/main container), then 0, 0 for row, column is correct. |
441 if (VisibleBrowserActions() != 0) { | 441 if (VisibleBrowserActions() != 0) { |
442 // Figure out where to display the indicator. This is a complex calculation: | 442 // Figure out where to display the indicator. This is a complex calculation: |
443 | 443 |
444 // First, we subtract out the padding to the left of the icon area, which is | 444 // First, we subtract out the padding to the left of the icon area, which is |
445 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the | 445 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the |
446 // event.x() so that our calculations are consistent with left-to-right. | 446 // event.x() so that our calculations are consistent with left-to-right. |
447 int offset_into_icon_area = | 447 int offset_into_icon_area = |
448 GetMirroredXInView(event.x()) - ToolbarView::kStandardSpacing; | 448 GetMirroredXInView(event.x()) - ToolbarView::kStandardSpacing; |
449 | 449 |
450 // Next, figure out what row we're on. This only matters for overflow mode, | 450 // Next, figure out what row we're on. This only matters for overflow mode, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // correct when dragging an icon to the left. When dragging to the right, | 535 // correct when dragging an icon to the left. When dragging to the right, |
536 // however, we want the icon being dragged to get the index of the item to | 536 // however, we want the icon being dragged to get the index of the item to |
537 // the left of the drop indicator, so we subtract one. | 537 // the left of the drop indicator, so we subtract one. |
538 // * Well, it can also point to the end, but not when dragging to the left. :) | 538 // * Well, it can also point to the end, but not when dragging to the left. :) |
539 if (i > data.index()) | 539 if (i > data.index()) |
540 --i; | 540 --i; |
541 | 541 |
542 // If this was a drag between containers, we will have to adjust the number of | 542 // If this was a drag between containers, we will have to adjust the number of |
543 // visible icons. | 543 // visible icons. |
544 bool drag_between_containers = | 544 bool drag_between_containers = |
545 !browser_action_views_[data.index()]->visible(); | 545 !toolbar_action_views_[data.index()]->visible(); |
546 model_->MoveExtensionIcon(GetIdAt(data.index()), i); | 546 model_->MoveExtensionIcon(GetIdAt(data.index()), i); |
547 | 547 |
548 if (drag_between_containers) { | 548 if (drag_between_containers) { |
549 // Let the main container update the model. | 549 // Let the main container update the model. |
550 if (in_overflow_mode()) | 550 if (in_overflow_mode()) |
551 main_container_->NotifyActionMovedToOverflow(); | 551 main_container_->NotifyActionMovedToOverflow(); |
552 else // This is the main container. | 552 else // This is the main container. |
553 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | 553 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); |
554 } | 554 } |
555 | 555 |
556 OnDragExited(); // Perform clean up after dragging. | 556 OnDragExited(); // Perform clean up after dragging. |
557 return ui::DragDropTypes::DRAG_MOVE; | 557 return ui::DragDropTypes::DRAG_MOVE; |
558 } | 558 } |
559 | 559 |
560 void BrowserActionsContainer::GetAccessibleState( | 560 void BrowserActionsContainer::GetAccessibleState( |
561 ui::AXViewState* state) { | 561 ui::AXViewState* state) { |
562 state->role = ui::AX_ROLE_GROUP; | 562 state->role = ui::AX_ROLE_GROUP; |
563 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 563 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
564 } | 564 } |
565 | 565 |
566 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 566 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
567 const gfx::Point& press_pt, | 567 const gfx::Point& press_pt, |
568 OSExchangeData* data) { | 568 OSExchangeData* data) { |
569 DCHECK(data); | 569 DCHECK(data); |
570 | 570 |
571 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), | 571 ToolbarActionViews::iterator iter = std::find(toolbar_action_views_.begin(), |
572 browser_action_views_.end(), | 572 toolbar_action_views_.end(), |
573 sender); | 573 sender); |
574 DCHECK(iter != browser_action_views_.end()); | 574 DCHECK(iter != toolbar_action_views_.end()); |
575 ToolbarActionViewController* view_controller = (*iter)->view_controller(); | 575 ToolbarActionViewController* view_controller = (*iter)->view_controller(); |
576 drag_utils::SetDragImageOnDataObject( | 576 drag_utils::SetDragImageOnDataObject( |
577 view_controller->GetIconWithBadge(), | 577 view_controller->GetIconWithBadge(), |
578 press_pt.OffsetFromOrigin(), | 578 press_pt.OffsetFromOrigin(), |
579 data); | 579 data); |
580 // Fill in the remaining info. | 580 // Fill in the remaining info. |
581 BrowserActionDragData drag_data(view_controller->GetId(), | 581 BrowserActionDragData drag_data(view_controller->GetId(), |
582 iter - browser_action_views_.begin()); | 582 iter - toolbar_action_views_.begin()); |
583 drag_data.Write(profile_, data); | 583 drag_data.Write(profile_, data); |
584 } | 584 } |
585 | 585 |
586 int BrowserActionsContainer::GetDragOperationsForView(View* sender, | 586 int BrowserActionsContainer::GetDragOperationsForView(View* sender, |
587 const gfx::Point& p) { | 587 const gfx::Point& p) { |
588 return ui::DragDropTypes::DRAG_MOVE; | 588 return ui::DragDropTypes::DRAG_MOVE; |
589 } | 589 } |
590 | 590 |
591 bool BrowserActionsContainer::CanStartDragForView(View* sender, | 591 bool BrowserActionsContainer::CanStartDragForView(View* sender, |
592 const gfx::Point& press_pt, | 592 const gfx::Point& press_pt, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 652 |
653 gfx::NativeView BrowserActionsContainer::TestGetPopup() { | 653 gfx::NativeView BrowserActionsContainer::TestGetPopup() { |
654 return popup_owner_ ? | 654 return popup_owner_ ? |
655 popup_owner_->view_controller()->GetPopupNativeView() : | 655 popup_owner_->view_controller()->GetPopupNativeView() : |
656 NULL; | 656 NULL; |
657 } | 657 } |
658 | 658 |
659 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 659 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
660 // If the views haven't been initialized yet, wait for the next call to | 660 // If the views haven't been initialized yet, wait for the next call to |
661 // paint (one will be triggered by entering highlight mode). | 661 // paint (one will be triggered by entering highlight mode). |
662 if (model_->is_highlighting() && !browser_action_views_.empty() && | 662 if (model_->is_highlighting() && !toolbar_action_views_.empty() && |
663 !in_overflow_mode()) { | 663 !in_overflow_mode()) { |
664 views::Painter::PaintPainterAt( | 664 views::Painter::PaintPainterAt( |
665 canvas, highlight_painter_.get(), GetLocalBounds()); | 665 canvas, highlight_painter_.get(), GetLocalBounds()); |
666 } | 666 } |
667 | 667 |
668 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while | 668 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while |
669 // dragging (like we do for tab dragging). | 669 // dragging (like we do for tab dragging). |
670 if (drop_position_.get()) { | 670 if (drop_position_.get()) { |
671 // The two-pixel width drop indicator. | 671 // The two-pixel width drop indicator. |
672 static const int kDropIndicatorWidth = 2; | 672 static const int kDropIndicatorWidth = 2; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 browser_->profile(), | 719 browser_->profile(), |
720 parent()->GetFocusManager(), | 720 parent()->GetFocusManager(), |
721 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 721 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
722 this)); | 722 this)); |
723 } | 723 } |
724 | 724 |
725 // Initial toolbar button creation and placement in the widget hierarchy. | 725 // Initial toolbar button creation and placement in the widget hierarchy. |
726 // We do this here instead of in the constructor because AddBrowserAction | 726 // We do this here instead of in the constructor because AddBrowserAction |
727 // calls Layout on the Toolbar, which needs this object to be constructed | 727 // calls Layout on the Toolbar, which needs this object to be constructed |
728 // before its Layout function is called. | 728 // before its Layout function is called. |
729 CreateBrowserActionViews(); | 729 CreateToolbarActionViews(); |
730 } | 730 } |
731 } | 731 } |
732 | 732 |
733 // static | 733 // static |
734 int BrowserActionsContainer::IconWidth(bool include_padding) { | 734 int BrowserActionsContainer::IconWidth(bool include_padding) { |
735 static bool initialized = false; | 735 static bool initialized = false; |
736 static int icon_width = 0; | 736 static int icon_width = 0; |
737 if (!initialized) { | 737 if (!initialized) { |
738 initialized = true; | 738 initialized = true; |
739 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 739 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
(...skipping 14 matching lines...) Expand all Loading... |
754 return icon_height; | 754 return icon_height; |
755 } | 755 } |
756 | 756 |
757 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, | 757 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, |
758 int index) { | 758 int index) { |
759 DCHECK(!GetViewForExtension(extension)) << | 759 DCHECK(!GetViewForExtension(extension)) << |
760 "Asked to add a browser action view for an extension that already exists"; | 760 "Asked to add a browser action view for an extension that already exists"; |
761 if (chevron_) | 761 if (chevron_) |
762 chevron_->CloseMenu(); | 762 chevron_->CloseMenu(); |
763 | 763 |
764 // Add the new browser action to the vector and the view hierarchy. | 764 // Add the new action to the vector and the view hierarchy. |
765 BrowserActionView* view = new BrowserActionView( | 765 ToolbarActionView* view = new ToolbarActionView( |
766 make_scoped_ptr(new ExtensionActionViewController( | 766 make_scoped_ptr(new ExtensionActionViewController( |
767 extension, | 767 extension, |
768 browser_, | 768 browser_, |
769 extensions::ExtensionActionManager::Get(profile_)-> | 769 extensions::ExtensionActionManager::Get(profile_)-> |
770 GetExtensionAction(*extension))), | 770 GetExtensionAction(*extension))), |
771 browser_, | 771 browser_, |
772 this); | 772 this); |
773 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 773 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); |
774 AddChildViewAt(view, index); | 774 AddChildViewAt(view, index); |
775 | 775 |
776 // If we are still initializing the container, don't bother animating. | 776 // If we are still initializing the container, don't bother animating. |
777 if (!model_->extensions_initialized()) | 777 if (!model_->extensions_initialized()) |
778 return; | 778 return; |
779 | 779 |
780 // If this is just an upgrade, then don't worry about resizing. | 780 // If this is just an upgrade, then don't worry about resizing. |
781 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 781 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
782 IsBeingUpgraded(extension)) { | 782 IsBeingUpgraded(extension)) { |
783 // We need to resize if either: | 783 // We need to resize if either: |
784 // - The container is set to display all icons (visible count = -1), or | 784 // - The container is set to display all icons (visible count = -1), or |
785 // - The container will need to expand to include the chevron. This can | 785 // - The container will need to expand to include the chevron. This can |
786 // happen when the container is set to display <n> icons, where <n> is | 786 // happen when the container is set to display <n> icons, where <n> is |
787 // the number of icons before the new icon. With the new icon, the chevron | 787 // the number of icons before the new icon. With the new icon, the chevron |
788 // will need to be displayed. | 788 // will need to be displayed. |
789 int model_icon_count = model_->GetVisibleIconCount(); | 789 int model_icon_count = model_->GetVisibleIconCount(); |
790 if (model_icon_count == -1 || | 790 if (model_icon_count == -1 || |
791 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() && | 791 (static_cast<size_t>(model_icon_count) < toolbar_action_views_.size() && |
792 (chevron_ && !chevron_->visible()))) { | 792 (chevron_ && !chevron_->visible()))) { |
793 suppress_chevron_ = true; | 793 suppress_chevron_ = true; |
794 Animate(gfx::Tween::LINEAR, GetIconCount()); | 794 Animate(gfx::Tween::LINEAR, GetIconCount()); |
795 return; | 795 return; |
796 } | 796 } |
797 } | 797 } |
798 | 798 |
799 // Otherwise, we don't have to resize, so just redraw the (possibly modified) | 799 // Otherwise, we don't have to resize, so just redraw the (possibly modified) |
800 // visible icon set. | 800 // visible icon set. |
801 OnBrowserActionVisibilityChanged(); | 801 OnBrowserActionVisibilityChanged(); |
802 } | 802 } |
803 | 803 |
804 void BrowserActionsContainer::ToolbarExtensionRemoved( | 804 void BrowserActionsContainer::ToolbarExtensionRemoved( |
805 const Extension* extension) { | 805 const Extension* extension) { |
806 if (chevron_) | 806 if (chevron_) |
807 chevron_->CloseMenu(); | 807 chevron_->CloseMenu(); |
808 | 808 |
809 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 809 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
810 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 810 for (ToolbarActionViews::iterator i(toolbar_action_views_.begin()); |
811 i != browser_action_views_.end(); ++i) { | 811 i != toolbar_action_views_.end(); ++i) { |
812 if ((*i)->view_controller()->GetId() == extension->id()) { | 812 if ((*i)->view_controller()->GetId() == extension->id()) { |
813 delete *i; | 813 delete *i; |
814 browser_action_views_.erase(i); | 814 toolbar_action_views_.erase(i); |
815 | 815 |
816 // If the extension is being upgraded we don't want the bar to shrink | 816 // If the extension is being upgraded we don't want the bar to shrink |
817 // because the icon is just going to get re-added to the same location. | 817 // because the icon is just going to get re-added to the same location. |
818 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 818 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
819 IsBeingUpgraded(extension)) | 819 IsBeingUpgraded(extension)) |
820 return; | 820 return; |
821 | 821 |
822 if (browser_action_views_.size() > visible_actions) { | 822 if (toolbar_action_views_.size() > visible_actions) { |
823 // If we have more icons than we can show, then we must not be changing | 823 // If we have more icons than we can show, then we must not be changing |
824 // the container size (since we either removed an icon from the main | 824 // the container size (since we either removed an icon from the main |
825 // area and one from the overflow list will have shifted in, or we | 825 // area and one from the overflow list will have shifted in, or we |
826 // removed an entry directly from the overflow list). | 826 // removed an entry directly from the overflow list). |
827 OnBrowserActionVisibilityChanged(); | 827 OnBrowserActionVisibilityChanged(); |
828 } else { | 828 } else { |
829 // Either we went from overflow to no-overflow, or we shrunk the no- | 829 // Either we went from overflow to no-overflow, or we shrunk the no- |
830 // overflow container by 1. Either way the size changed, so animate. | 830 // overflow container by 1. Either way the size changed, so animate. |
831 if (chevron_) | 831 if (chevron_) |
832 chevron_->SetVisible(false); | 832 chevron_->SetVisible(false); |
833 Animate(gfx::Tween::EASE_OUT, browser_action_views_.size()); | 833 Animate(gfx::Tween::EASE_OUT, toolbar_action_views_.size()); |
834 } | 834 } |
835 return; // We have found the action to remove, bail out. | 835 return; // We have found the action to remove, bail out. |
836 } | 836 } |
837 } | 837 } |
838 } | 838 } |
839 | 839 |
840 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, | 840 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, |
841 int index) { | 841 int index) { |
842 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 842 DCHECK(index >= 0 && index < static_cast<int>(toolbar_action_views_.size())); |
843 | 843 |
844 BrowserActionViews::iterator iter = browser_action_views_.begin(); | 844 ToolbarActionViews::iterator iter = toolbar_action_views_.begin(); |
845 while (iter != browser_action_views_.end() && | 845 while (iter != toolbar_action_views_.end() && |
846 (*iter)->view_controller()->GetId() != extension->id()) | 846 (*iter)->view_controller()->GetId() != extension->id()) |
847 ++iter; | 847 ++iter; |
848 | 848 |
849 DCHECK(iter != browser_action_views_.end()); | 849 DCHECK(iter != toolbar_action_views_.end()); |
850 if (iter - browser_action_views_.begin() == index) | 850 if (iter - toolbar_action_views_.begin() == index) |
851 return; // Already in place. | 851 return; // Already in place. |
852 | 852 |
853 BrowserActionView* moved_view = *iter; | 853 ToolbarActionView* moved_view = *iter; |
854 browser_action_views_.erase(iter); | 854 toolbar_action_views_.erase(iter); |
855 browser_action_views_.insert( | 855 toolbar_action_views_.insert( |
856 browser_action_views_.begin() + index, moved_view); | 856 toolbar_action_views_.begin() + index, moved_view); |
857 | 857 |
858 Layout(); | 858 Layout(); |
859 SchedulePaint(); | 859 SchedulePaint(); |
860 } | 860 } |
861 | 861 |
862 void BrowserActionsContainer::ToolbarExtensionUpdated( | 862 void BrowserActionsContainer::ToolbarExtensionUpdated( |
863 const Extension* extension) { | 863 const Extension* extension) { |
864 BrowserActionView* view = GetViewForExtension(extension); | 864 ToolbarActionView* view = GetViewForExtension(extension); |
865 // There might not be a view in cases where we are highlighting or if we | 865 // There might not be a view in cases where we are highlighting or if we |
866 // haven't fully initialized extensions. | 866 // haven't fully initialized extensions. |
867 if (view) | 867 if (view) |
868 view->UpdateState(); | 868 view->UpdateState(); |
869 } | 869 } |
870 | 870 |
871 bool BrowserActionsContainer::ShowExtensionActionPopup( | 871 bool BrowserActionsContainer::ShowExtensionActionPopup( |
872 const Extension* extension, | 872 const Extension* extension, |
873 bool grant_active_tab) { | 873 bool grant_active_tab) { |
874 // Don't override another popup, and only show in the active window. | 874 // Don't override another popup, and only show in the active window. |
875 if (popup_owner_ || !browser_->window()->IsActive()) | 875 if (popup_owner_ || !browser_->window()->IsActive()) |
876 return false; | 876 return false; |
877 | 877 |
878 BrowserActionView* view = GetViewForExtension(extension); | 878 ToolbarActionView* view = GetViewForExtension(extension); |
879 return view && view->view_controller()->ExecuteAction(grant_active_tab); | 879 return view && view->view_controller()->ExecuteAction(grant_active_tab); |
880 } | 880 } |
881 | 881 |
882 void BrowserActionsContainer::ToolbarVisibleCountChanged() { | 882 void BrowserActionsContainer::ToolbarVisibleCountChanged() { |
883 if (GetPreferredWidth() != container_width_) | 883 if (GetPreferredWidth() != container_width_) |
884 Animate(gfx::Tween::EASE_OUT, GetIconCount()); | 884 Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
885 } | 885 } |
886 | 886 |
887 void BrowserActionsContainer::ToolbarHighlightModeChanged( | 887 void BrowserActionsContainer::ToolbarHighlightModeChanged( |
888 bool is_highlighting) { | 888 bool is_highlighting) { |
889 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 889 // The visual highlighting is done in OnPaint(). It's a bit of a pain that |
890 // we delete and recreate everything here, but given everything else going on | 890 // we delete and recreate everything here, but given everything else going on |
891 // (the lack of highlight, n more extensions appearing, etc), it's not worth | 891 // (the lack of highlight, n more extensions appearing, etc), it's not worth |
892 // the extra complexity to create and insert only the new extensions. | 892 // the extra complexity to create and insert only the new extensions. |
893 DeleteBrowserActionViews(); | 893 DeleteToolbarActionViews(); |
894 CreateBrowserActionViews(); | 894 CreateToolbarActionViews(); |
895 Animate(gfx::Tween::LINEAR, GetIconCount()); | 895 Animate(gfx::Tween::LINEAR, GetIconCount()); |
896 } | 896 } |
897 | 897 |
898 Browser* BrowserActionsContainer::GetBrowser() { | 898 Browser* BrowserActionsContainer::GetBrowser() { |
899 return browser_; | 899 return browser_; |
900 } | 900 } |
901 | 901 |
902 void BrowserActionsContainer::LoadImages() { | 902 void BrowserActionsContainer::LoadImages() { |
903 if (in_overflow_mode()) | 903 if (in_overflow_mode()) |
904 return; // Overflow mode has neither a chevron nor highlighting. | 904 return; // Overflow mode has neither a chevron nor highlighting. |
905 | 905 |
906 ui::ThemeProvider* tp = GetThemeProvider(); | 906 ui::ThemeProvider* tp = GetThemeProvider(); |
907 if (tp && chevron_) { | 907 if (tp && chevron_) { |
908 chevron_->SetImage(views::Button::STATE_NORMAL, | 908 chevron_->SetImage(views::Button::STATE_NORMAL, |
909 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 909 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
910 } | 910 } |
911 | 911 |
912 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 912 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
913 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 913 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
914 } | 914 } |
915 | 915 |
916 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 916 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
917 SetVisible(!browser_action_views_.empty()); | 917 SetVisible(!toolbar_action_views_.empty()); |
918 if (parent()) { // Parent can be null in testing. | 918 if (parent()) { // Parent can be null in testing. |
919 parent()->Layout(); | 919 parent()->Layout(); |
920 parent()->SchedulePaint(); | 920 parent()->SchedulePaint(); |
921 } | 921 } |
922 } | 922 } |
923 | 923 |
924 int BrowserActionsContainer::GetPreferredWidth() { | 924 int BrowserActionsContainer::GetPreferredWidth() { |
925 return IconCountToWidth(GetIconCount()); | 925 return IconCountToWidth(GetIconCount()); |
926 } | 926 } |
927 | 927 |
928 void BrowserActionsContainer::SetChevronVisibility() { | 928 void BrowserActionsContainer::SetChevronVisibility() { |
929 if (chevron_) { | 929 if (chevron_) { |
930 chevron_->SetVisible( | 930 chevron_->SetVisible( |
931 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); | 931 VisibleBrowserActionsAfterAnimation() < toolbar_action_views_.size()); |
932 } | 932 } |
933 } | 933 } |
934 | 934 |
935 int BrowserActionsContainer::IconCountToWidth(int icons) const { | 935 int BrowserActionsContainer::IconCountToWidth(int icons) const { |
936 if (icons < 0) | 936 if (icons < 0) |
937 icons = browser_action_views_.size(); | 937 icons = toolbar_action_views_.size(); |
938 bool display_chevron = | 938 bool display_chevron = |
939 chevron_ && static_cast<size_t>(icons) < browser_action_views_.size(); | 939 chevron_ && static_cast<size_t>(icons) < toolbar_action_views_.size(); |
940 if (icons == 0 && !display_chevron) | 940 if (icons == 0 && !display_chevron) |
941 return ToolbarView::kStandardSpacing; | 941 return ToolbarView::kStandardSpacing; |
942 int icons_size = | 942 int icons_size = |
943 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 943 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
944 int chevron_size = display_chevron ? | 944 int chevron_size = display_chevron ? |
945 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 945 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
946 // In overflow mode, our padding is to use item spacing on either end (just so | 946 // In overflow mode, our padding is to use item spacing on either end (just so |
947 // we can see the drop indicator). Otherwise we use the standard toolbar | 947 // we can see the drop indicator). Otherwise we use the standard toolbar |
948 // spacing. | 948 // spacing. |
949 // Note: These are actually the same thing, but, on the offchance one | 949 // Note: These are actually the same thing, but, on the offchance one |
950 // changes, let's get it right. | 950 // changes, let's get it right. |
951 int padding = | 951 int padding = |
952 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing); | 952 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing); |
953 return icons_size + chevron_size + padding; | 953 return icons_size + chevron_size + padding; |
954 } | 954 } |
955 | 955 |
956 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 956 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
957 // Check for widths large enough to show the entire icon set. | 957 // Check for widths large enough to show the entire icon set. |
958 if (pixels >= IconCountToWidth(-1)) | 958 if (pixels >= IconCountToWidth(-1)) |
959 return browser_action_views_.size(); | 959 return toolbar_action_views_.size(); |
960 | 960 |
961 // We reserve space for the padding on either side of the toolbar... | 961 // We reserve space for the padding on either side of the toolbar... |
962 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); | 962 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); |
963 // ... and, if the chevron is enabled, the chevron. | 963 // ... and, if the chevron is enabled, the chevron. |
964 if (chevron_) | 964 if (chevron_) |
965 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); | 965 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); |
966 | 966 |
967 // Now we add an extra between-item padding value so the space can be divided | 967 // Now we add an extra between-item padding value so the space can be divided |
968 // evenly by (size of icon with padding). | 968 // evenly by (size of icon with padding). |
969 return static_cast<size_t>( | 969 return static_cast<size_t>( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 int model_visible_size = model_->GetVisibleIconCount(); | 1001 int model_visible_size = model_->GetVisibleIconCount(); |
1002 size_t absolute_model_visible_size = model_visible_size == -1 ? | 1002 size_t absolute_model_visible_size = model_visible_size == -1 ? |
1003 model_->toolbar_items().size() : model_visible_size; | 1003 model_->toolbar_items().size() : model_visible_size; |
1004 | 1004 |
1005 #if !defined(NDEBUG) | 1005 #if !defined(NDEBUG) |
1006 // Good time for some sanity checks: We should never try to display more | 1006 // Good time for some sanity checks: We should never try to display more |
1007 // icons than we have, and we should always have a view per item in the model. | 1007 // icons than we have, and we should always have a view per item in the model. |
1008 // (The only exception is if this is in initialization.) | 1008 // (The only exception is if this is in initialization.) |
1009 if (initialized_) { | 1009 if (initialized_) { |
1010 size_t num_extension_actions = 0u; | 1010 size_t num_extension_actions = 0u; |
1011 for (BrowserActionView* view : browser_action_views_) { | 1011 for (ToolbarActionView* view : toolbar_action_views_) { |
1012 // No component action should ever have a valid extension id, so we can | 1012 // No component action should ever have a valid extension id, so we can |
1013 // use this to check the extension amount. | 1013 // use this to check the extension amount. |
1014 // TODO(devlin): Fix this to just check model size when the model also | 1014 // TODO(devlin): Fix this to just check model size when the model also |
1015 // includes component actions. | 1015 // includes component actions. |
1016 if (crx_file::id_util::IdIsValid(view->view_controller()->GetId())) | 1016 if (crx_file::id_util::IdIsValid(view->view_controller()->GetId())) |
1017 ++num_extension_actions; | 1017 ++num_extension_actions; |
1018 } | 1018 } |
1019 DCHECK_LE(absolute_model_visible_size, num_extension_actions); | 1019 DCHECK_LE(absolute_model_visible_size, num_extension_actions); |
1020 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); | 1020 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); |
1021 } | 1021 } |
1022 #endif | 1022 #endif |
1023 | 1023 |
1024 // The overflow displays any icons not shown by the main bar. | 1024 // The overflow displays any icons not shown by the main bar. |
1025 return in_overflow_mode() ? | 1025 return in_overflow_mode() ? |
1026 model_->toolbar_items().size() - absolute_model_visible_size : | 1026 model_->toolbar_items().size() - absolute_model_visible_size : |
1027 absolute_model_visible_size; | 1027 absolute_model_visible_size; |
1028 } | 1028 } |
OLD | NEW |