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