Chromium Code Reviews| 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/view_ids.h" | 15 #include "chrome/browser/ui/view_ids.h" |
| 16 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 16 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 17 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 17 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | 19 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
| 20 #include "chrome/browser/ui/views/toolbar/chrome_actions_registry.h" | |
| 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 21 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 21 #include "chrome/common/extensions/command.h" | 22 #include "chrome/common/extensions/command.h" |
| 22 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 24 #include "extensions/browser/runtime_data.h" | 25 #include "extensions/browser/runtime_data.h" |
| 25 #include "extensions/common/feature_switch.h" | 26 #include "extensions/common/feature_switch.h" |
| 26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 27 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 28 #include "ui/accessibility/ax_view_state.h" | 29 #include "ui/accessibility/ax_view_state.h" |
| 29 #include "ui/base/dragdrop/drag_utils.h" | 30 #include "ui/base/dragdrop/drag_utils.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 124 } |
| 124 | 125 |
| 125 BrowserActionsContainer::~BrowserActionsContainer() { | 126 BrowserActionsContainer::~BrowserActionsContainer() { |
| 126 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 127 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 127 observers_, | 128 observers_, |
| 128 OnBrowserActionsContainerDestroyed()); | 129 OnBrowserActionsContainerDestroyed()); |
| 129 | 130 |
| 130 if (model_) | 131 if (model_) |
| 131 model_->RemoveObserver(this); | 132 model_->RemoveObserver(this); |
| 132 HideActivePopup(); | 133 HideActivePopup(); |
| 133 DeleteBrowserActionViews(); | 134 DeleteActionViews(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void BrowserActionsContainer::Init() { | 137 void BrowserActionsContainer::Init() { |
| 137 LoadImages(); | 138 LoadImages(); |
| 138 | 139 |
| 139 // We wait to set the container width until now so that the chevron images | 140 // We wait to set the container width until now so that the chevron images |
| 140 // will be loaded. The width calculation needs to know the chevron size. | 141 // will be loaded. The width calculation needs to know the chevron size. |
| 141 if (model_ && model_->extensions_initialized()) { | 142 if (model_ && model_->extensions_initialized()) { |
| 142 container_width_ = GetPreferredWidth(); | 143 container_width_ = GetPreferredWidth(); |
| 143 SetChevronVisibility(); | 144 SetChevronVisibility(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 initialized_ = true; | 147 initialized_ = true; |
| 147 } | 148 } |
| 148 | 149 |
| 149 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 150 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
| 150 const Extension* extension) { | 151 const Extension* extension) { |
| 151 for (BrowserActionView* view : browser_action_views_) { | 152 for (BrowserActionView* view : browser_action_views_) { |
| 152 if (view->extension() == extension) | 153 if (view->GetExtensionActionViewController()->extension() == extension) |
| 153 return view; | 154 return view; |
| 154 } | 155 } |
| 155 return NULL; | 156 return NULL; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void BrowserActionsContainer::RefreshBrowserActionViews() { | 159 const Extension* BrowserActionsContainer::GetExtensionAt(size_t index) const { |
| 160 return browser_action_views_[index]->GetExtensionActionViewController()-> | |
| 161 extension(); | |
| 162 } | |
| 163 | |
| 164 void BrowserActionsContainer::RefreshActionViews() { | |
| 159 for (BrowserActionView* view : browser_action_views_) | 165 for (BrowserActionView* view : browser_action_views_) |
| 160 view->UpdateState(); | 166 view->UpdateState(); |
| 167 for (BrowserActionView* view : chrome_action_views_) | |
| 168 view->UpdateState(); | |
| 161 } | 169 } |
| 162 | 170 |
| 163 void BrowserActionsContainer::CreateBrowserActionViews() { | 171 void BrowserActionsContainer::CreateActionViews() { |
| 164 DCHECK(browser_action_views_.empty()); | 172 DCHECK(browser_action_views_.empty()); |
| 165 if (!model_) | 173 if (!model_) |
| 166 return; | 174 return; |
| 167 | 175 |
| 168 extensions::ExtensionActionManager* action_manager = | 176 extensions::ExtensionActionManager* action_manager = |
| 169 extensions::ExtensionActionManager::Get(profile_); | 177 extensions::ExtensionActionManager::Get(profile_); |
| 170 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | 178 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); |
|
sky
2014/10/15 23:52:30
Seems like there should be one unified presentatio
Devlin
2014/10/16 16:46:38
In a perfect world, yes. But that will lead to a
sky
2014/10/16 18:13:39
I think it's possible to do this incrementally. No
Devlin
2014/10/16 22:05:27
I'm curious what you think of Patch Set 3's approa
| |
| 171 for (const scoped_refptr<const Extension>& extension : toolbar_items) { | 179 for (const scoped_refptr<const Extension>& extension : toolbar_items) { |
| 172 BrowserActionView* view = | 180 BrowserActionView* view = new BrowserActionView( |
| 173 new BrowserActionView(extension.get(), | 181 make_scoped_ptr(new ExtensionActionViewController( |
| 174 action_manager->GetExtensionAction(*extension), | 182 extension.get(), |
| 175 browser_, | 183 browser_, |
| 176 this); | 184 action_manager->GetExtensionAction(*extension), |
| 185 NULL)), | |
| 186 BrowserActionView::TYPE_EXTENSION_ACTION, | |
| 187 browser_, | |
| 188 this); | |
| 177 browser_action_views_.push_back(view); | 189 browser_action_views_.push_back(view); |
| 178 AddChildView(view); | 190 AddChildView(view); |
| 179 } | 191 } |
| 192 | |
| 193 ScopedVector<ToolbarActionViewController> chrome_actions = | |
| 194 ChromeActionsRegistry::GetChromeActions(); | |
| 195 DCHECK(extensions::FeatureSwitch::extension_action_redesign()->IsEnabled() || | |
| 196 chrome_actions.empty()); | |
| 197 for (ToolbarActionViewController* controller : chrome_actions) { | |
| 198 BrowserActionView* view = new BrowserActionView( | |
| 199 make_scoped_ptr(controller), | |
| 200 BrowserActionView::TYPE_CHROME_ACTION, | |
| 201 browser_, | |
| 202 this); | |
| 203 chrome_action_views_.push_back(view); | |
| 204 AddChildView(view); | |
| 205 } | |
| 206 chrome_actions.weak_clear(); | |
| 180 } | 207 } |
| 181 | 208 |
| 182 void BrowserActionsContainer::DeleteBrowserActionViews() { | 209 void BrowserActionsContainer::DeleteActionViews() { |
| 183 HideActivePopup(); | 210 HideActivePopup(); |
| 184 STLDeleteElements(&browser_action_views_); | 211 STLDeleteElements(&browser_action_views_); |
| 212 STLDeleteElements(&chrome_action_views_); | |
| 185 } | 213 } |
| 186 | 214 |
| 187 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 215 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 188 size_t visible_actions = 0; | 216 size_t visible_actions = 0; |
| 189 for (const BrowserActionView* view : browser_action_views_) { | 217 for (const BrowserActionView* view : browser_action_views_) { |
| 190 if (view->visible()) | 218 if (view->visible()) |
| 191 ++visible_actions; | 219 ++visible_actions; |
| 192 } | 220 } |
| 193 return visible_actions; | 221 return visible_actions; |
| 194 } | 222 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 DCHECK((!popup_owner_ && popup_owner) || | 275 DCHECK((!popup_owner_ && popup_owner) || |
| 248 (popup_owner_ && !popup_owner)); | 276 (popup_owner_ && !popup_owner)); |
| 249 popup_owner_ = popup_owner; | 277 popup_owner_ = popup_owner; |
| 250 } | 278 } |
| 251 | 279 |
| 252 void BrowserActionsContainer::HideActivePopup() { | 280 void BrowserActionsContainer::HideActivePopup() { |
| 253 if (popup_owner_) | 281 if (popup_owner_) |
| 254 popup_owner_->view_controller()->HidePopup(); | 282 popup_owner_->view_controller()->HidePopup(); |
| 255 } | 283 } |
| 256 | 284 |
| 257 BrowserActionView* BrowserActionsContainer::GetMainViewForExtension( | 285 BrowserActionView* BrowserActionsContainer::GetMainViewForAction( |
| 258 const Extension* extension) { | 286 BrowserActionView* view) { |
| 259 return in_overflow_mode() ? | 287 if (!in_overflow_mode()) |
| 260 main_container_->GetViewForExtension(extension) : | 288 return view; // This is the main view. |
| 261 GetViewForExtension(extension); | 289 |
| 290 // The overflow container and main container each have the same views and | |
| 291 // view indices, so we can return the view of the index that |view| has in | |
| 292 // this container. | |
| 293 bool is_extension_action = | |
| 294 view->type() == BrowserActionView::TYPE_EXTENSION_ACTION; | |
| 295 const BrowserActionViews& views = | |
| 296 is_extension_action ? browser_action_views_ : chrome_action_views_; | |
| 297 BrowserActionViews::const_iterator iter = | |
| 298 std::find(views.begin(), views.end(), view); | |
| 299 DCHECK(iter != views.end()); | |
| 300 size_t index = iter - views.begin(); | |
| 301 return is_extension_action ? | |
| 302 main_container_->browser_action_views_[index] : | |
| 303 main_container_->chrome_action_views_[index]; | |
| 262 } | 304 } |
| 263 | 305 |
| 264 void BrowserActionsContainer::AddObserver( | 306 void BrowserActionsContainer::AddObserver( |
| 265 BrowserActionsContainerObserver* observer) { | 307 BrowserActionsContainerObserver* observer) { |
| 266 observers_.AddObserver(observer); | 308 observers_.AddObserver(observer); |
| 267 } | 309 } |
| 268 | 310 |
| 269 void BrowserActionsContainer::RemoveObserver( | 311 void BrowserActionsContainer::RemoveObserver( |
| 270 BrowserActionsContainerObserver* observer) { | 312 BrowserActionsContainerObserver* observer) { |
| 271 observers_.RemoveObserver(observer); | 313 observers_.RemoveObserver(observer); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); | 347 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); |
| 306 return GetPreferredSize().height(); | 348 return GetPreferredSize().height(); |
| 307 } | 349 } |
| 308 | 350 |
| 309 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 351 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
| 310 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); | 352 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); |
| 311 return gfx::Size(min_width, IconHeight()); | 353 return gfx::Size(min_width, IconHeight()); |
| 312 } | 354 } |
| 313 | 355 |
| 314 void BrowserActionsContainer::Layout() { | 356 void BrowserActionsContainer::Layout() { |
| 315 if (browser_action_views_.empty()) { | 357 if (browser_action_views_.empty() && chrome_action_views_.empty()) { |
| 316 SetVisible(false); | 358 SetVisible(false); |
| 317 return; | 359 return; |
| 318 } | 360 } |
| 319 | 361 |
| 320 SetVisible(true); | 362 SetVisible(true); |
| 321 if (resize_area_) | 363 if (resize_area_) |
| 322 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 364 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
| 323 | 365 |
| 324 // If the icons don't all fit, show the chevron (unless suppressed). | 366 // If the icons don't all fit, show the chevron (unless suppressed). |
| 325 int max_x = GetPreferredSize().width(); | 367 int max_x = GetPreferredSize().width(); |
| 326 if (IconCountToWidth(-1) > max_x && !suppress_chevron_ && chevron_) { | 368 if (IconCountToWidth(-1) > max_x && !suppress_chevron_ && chevron_) { |
| 327 chevron_->SetVisible(true); | 369 chevron_->SetVisible(true); |
| 328 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 370 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
| 329 max_x -= chevron_size.width() + kChevronSpacing; | 371 max_x -= chevron_size.width() + kChevronSpacing; |
| 330 chevron_->SetBounds( | 372 chevron_->SetBounds( |
| 331 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 373 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
| 332 0, | 374 0, |
| 333 chevron_size.width(), | 375 chevron_size.width(), |
| 334 chevron_size.height()); | 376 chevron_size.height()); |
| 335 } else if (chevron_) { | 377 } else if (chevron_) { |
| 336 chevron_->SetVisible(false); | 378 chevron_->SetVisible(false); |
| 337 } | 379 } |
| 338 | 380 |
| 381 // Construct a single vector of all views to draw to ease calculation (since | |
| 382 // this only copies pointers, it's cheap). | |
| 383 BrowserActionViews views(browser_action_views_.begin(), | |
| 384 browser_action_views_.end()); | |
| 385 views.insert(views.end(), | |
| 386 chrome_action_views_.begin(), | |
| 387 chrome_action_views_.end()); | |
| 388 | |
| 339 // The padding before the first icon and after the last icon in the container. | 389 // The padding before the first icon and after the last icon in the container. |
| 340 int container_padding = | 390 int container_padding = |
| 341 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing; | 391 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing; |
| 342 // The range of visible icons, from start_index (inclusive) to end_index | 392 // The range of visible icons, from start_index (inclusive) to end_index |
| 343 // (exclusive). | 393 // (exclusive). |
| 344 size_t start_index = in_overflow_mode() ? | 394 size_t start_index = in_overflow_mode() ? |
| 345 main_container_->VisibleBrowserActionsAfterAnimation() : 0u; | 395 main_container_->VisibleBrowserActionsAfterAnimation() : 0u; |
| 346 // For the main container's last visible icon, we calculate how many icons we | 396 // For the main container's last visible icon, we calculate how many icons we |
| 347 // can display with the given width. We add an extra kItemSpacing because the | 397 // can display with the given width. We add an extra kItemSpacing because the |
| 348 // last icon doesn't need padding, but we want it to divide easily. | 398 // last icon doesn't need padding, but we want it to divide easily. |
| 349 size_t end_index = in_overflow_mode() ? | 399 size_t end_index = in_overflow_mode() ? |
| 350 browser_action_views_.size() : | 400 views.size() : |
| 351 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true); | 401 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true); |
| 352 // The maximum length for one row of icons. | 402 // The maximum length for one row of icons. |
| 353 size_t row_length = | 403 size_t row_length = |
| 354 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index; | 404 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index; |
| 355 | 405 |
| 356 // Now draw the icons for the browser actions in the available space. Once | 406 // Now draw the icons for the browser actions in the available space. Once |
| 357 // all the variables are in place, the layout works equally well for the main | 407 // all the variables are in place, the layout works equally well for the main |
| 358 // and overflow container. | 408 // and overflow container. |
| 359 for (size_t i = 0u; i < browser_action_views_.size(); ++i) { | 409 for (size_t i = 0u; i < views.size(); ++i) { |
| 360 BrowserActionView* view = browser_action_views_[i]; | 410 BrowserActionView* view = views[i]; |
| 361 if (i < start_index || i >= end_index) { | 411 if (i < start_index || i >= end_index) { |
| 362 view->SetVisible(false); | 412 view->SetVisible(false); |
| 363 } else { | 413 } else { |
| 364 size_t relative_index = i - start_index; | 414 size_t relative_index = i - start_index; |
| 365 size_t index_in_row = relative_index % row_length; | 415 size_t index_in_row = relative_index % row_length; |
| 366 size_t row_index = relative_index / row_length; | 416 size_t row_index = relative_index / row_length; |
| 367 view->SetBounds(container_padding + index_in_row * IconWidth(true), | 417 view->SetBounds(container_padding + index_in_row * IconWidth(true), |
| 368 row_index * IconHeight(), | 418 row_index * IconHeight(), |
| 369 IconWidth(false), | 419 IconWidth(false), |
| 370 IconHeight()); | 420 IconHeight()); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 SchedulePaint(); | 522 SchedulePaint(); |
| 473 } | 523 } |
| 474 | 524 |
| 475 int BrowserActionsContainer::OnPerformDrop( | 525 int BrowserActionsContainer::OnPerformDrop( |
| 476 const ui::DropTargetEvent& event) { | 526 const ui::DropTargetEvent& event) { |
| 477 BrowserActionDragData data; | 527 BrowserActionDragData data; |
| 478 if (!data.Read(event.data())) | 528 if (!data.Read(event.data())) |
| 479 return ui::DragDropTypes::DRAG_NONE; | 529 return ui::DragDropTypes::DRAG_NONE; |
| 480 | 530 |
| 481 // Make sure we have the same view as we started with. | 531 // Make sure we have the same view as we started with. |
| 482 DCHECK_EQ(browser_action_views_[data.index()]->extension()->id(), | 532 DCHECK_EQ(GetExtensionAt(data.index())->id(), data.id()); |
| 483 data.id()); | |
| 484 DCHECK(model_); | 533 DCHECK(model_); |
| 485 | 534 |
| 486 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + | 535 size_t i = drop_position_->row * icons_per_overflow_menu_row_ + |
| 487 drop_position_->icon_in_row; | 536 drop_position_->icon_in_row; |
| 488 if (in_overflow_mode()) | 537 if (in_overflow_mode()) |
| 489 i += main_container_->VisibleBrowserActionsAfterAnimation(); | 538 i += main_container_->VisibleBrowserActionsAfterAnimation(); |
| 490 // |i| now points to the item to the right of the drop indicator*, which is | 539 // |i| now points to the item to the right of the drop indicator*, which is |
| 491 // correct when dragging an icon to the left. When dragging to the right, | 540 // correct when dragging an icon to the left. When dragging to the right, |
| 492 // however, we want the icon being dragged to get the index of the item to | 541 // however, we want the icon being dragged to get the index of the item to |
| 493 // the left of the drop indicator, so we subtract one. | 542 // the left of the drop indicator, so we subtract one. |
| 494 // * Well, it can also point to the end, but not when dragging to the left. :) | 543 // * Well, it can also point to the end, but not when dragging to the left. :) |
| 495 if (i > data.index()) | 544 if (i > data.index()) |
| 496 --i; | 545 --i; |
| 497 | 546 |
| 498 // If this was a drag between containers, we will have to adjust the number of | 547 // If this was a drag between containers, we will have to adjust the number of |
| 499 // visible icons. | 548 // visible icons. |
| 500 bool drag_between_containers = | 549 bool drag_between_containers = |
| 501 !browser_action_views_[data.index()]->visible(); | 550 !browser_action_views_[data.index()]->visible(); |
| 502 model_->MoveExtensionIcon( | 551 model_->MoveExtensionIcon(GetExtensionAt(data.index()), i); |
| 503 browser_action_views_[data.index()]->extension(), i); | |
| 504 | 552 |
| 505 if (drag_between_containers) { | 553 if (drag_between_containers) { |
| 506 // Let the main container update the model. | 554 // Let the main container update the model. |
| 507 if (in_overflow_mode()) | 555 if (in_overflow_mode()) |
| 508 main_container_->NotifyActionMovedToOverflow(); | 556 main_container_->NotifyActionMovedToOverflow(); |
| 509 else // This is the main container. | 557 else // This is the main container. |
| 510 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | 558 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); |
| 511 } | 559 } |
| 512 | 560 |
| 513 OnDragExited(); // Perform clean up after dragging. | 561 OnDragExited(); // Perform clean up after dragging. |
| 514 return ui::DragDropTypes::DRAG_MOVE; | 562 return ui::DragDropTypes::DRAG_MOVE; |
| 515 } | 563 } |
| 516 | 564 |
| 517 void BrowserActionsContainer::GetAccessibleState( | 565 void BrowserActionsContainer::GetAccessibleState( |
| 518 ui::AXViewState* state) { | 566 ui::AXViewState* state) { |
| 519 state->role = ui::AX_ROLE_GROUP; | 567 state->role = ui::AX_ROLE_GROUP; |
| 520 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 568 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
| 521 } | 569 } |
| 522 | 570 |
| 523 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 571 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
| 524 const gfx::Point& press_pt, | 572 const gfx::Point& press_pt, |
| 525 OSExchangeData* data) { | 573 OSExchangeData* data) { |
| 526 DCHECK(data); | 574 DCHECK(data); |
| 527 | 575 |
| 528 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), | 576 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(), |
| 529 browser_action_views_.end(), | 577 browser_action_views_.end(), |
| 530 sender); | 578 sender); |
| 531 DCHECK(iter != browser_action_views_.end()); | 579 DCHECK(iter != browser_action_views_.end()); |
| 532 drag_utils::SetDragImageOnDataObject((*iter)->GetIconWithBadge(), | 580 ExtensionActionViewController* view_controller = |
| 581 (*iter)->GetExtensionActionViewController(); | |
| 582 drag_utils::SetDragImageOnDataObject(view_controller->GetIconWithBadge(), | |
| 533 press_pt.OffsetFromOrigin(), | 583 press_pt.OffsetFromOrigin(), |
| 534 data); | 584 data); |
| 535 // Fill in the remaining info. | 585 // Fill in the remaining info. |
| 536 BrowserActionDragData drag_data((*iter)->extension()->id(), | 586 BrowserActionDragData drag_data(view_controller->extension()->id(), |
| 537 iter - browser_action_views_.begin()); | 587 iter - browser_action_views_.begin()); |
| 538 drag_data.Write(profile_, data); | 588 drag_data.Write(profile_, data); |
| 539 } | 589 } |
| 540 | 590 |
| 541 int BrowserActionsContainer::GetDragOperationsForView(View* sender, | 591 int BrowserActionsContainer::GetDragOperationsForView(View* sender, |
| 542 const gfx::Point& p) { | 592 const gfx::Point& p) { |
| 543 return ui::DragDropTypes::DRAG_MOVE; | 593 return ui::DragDropTypes::DRAG_MOVE; |
| 544 } | 594 } |
| 545 | 595 |
| 546 bool BrowserActionsContainer::CanStartDragForView(View* sender, | 596 bool BrowserActionsContainer::CanStartDragForView(View* sender, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 extensions::ActiveTabPermissionGranter* | 649 extensions::ActiveTabPermissionGranter* |
| 600 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 650 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 601 content::WebContents* web_contents = GetCurrentWebContents(); | 651 content::WebContents* web_contents = GetCurrentWebContents(); |
| 602 if (!web_contents) | 652 if (!web_contents) |
| 603 return NULL; | 653 return NULL; |
| 604 return extensions::TabHelper::FromWebContents(web_contents)-> | 654 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 605 active_tab_permission_granter(); | 655 active_tab_permission_granter(); |
| 606 } | 656 } |
| 607 | 657 |
| 608 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 658 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
| 609 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 659 return popup_owner_ ? |
| 660 popup_owner_->GetExtensionActionViewController()->popup() : | |
| 661 NULL; | |
| 610 } | 662 } |
| 611 | 663 |
| 612 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 664 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
| 613 // If the views haven't been initialized yet, wait for the next call to | 665 // If the views haven't been initialized yet, wait for the next call to |
| 614 // paint (one will be triggered by entering highlight mode). | 666 // paint (one will be triggered by entering highlight mode). |
| 615 if (model_->is_highlighting() && !browser_action_views_.empty() && | 667 if (model_->is_highlighting() && !browser_action_views_.empty() && |
| 616 !in_overflow_mode()) { | 668 !in_overflow_mode()) { |
| 617 views::Painter::PaintPainterAt( | 669 views::Painter::PaintPainterAt( |
| 618 canvas, highlight_painter_.get(), GetLocalBounds()); | 670 canvas, highlight_painter_.get(), GetLocalBounds()); |
| 619 } | 671 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 browser_->profile(), | 724 browser_->profile(), |
| 673 parent()->GetFocusManager(), | 725 parent()->GetFocusManager(), |
| 674 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 726 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 675 this)); | 727 this)); |
| 676 } | 728 } |
| 677 | 729 |
| 678 // Initial toolbar button creation and placement in the widget hierarchy. | 730 // Initial toolbar button creation and placement in the widget hierarchy. |
| 679 // We do this here instead of in the constructor because AddBrowserAction | 731 // We do this here instead of in the constructor because AddBrowserAction |
| 680 // calls Layout on the Toolbar, which needs this object to be constructed | 732 // calls Layout on the Toolbar, which needs this object to be constructed |
| 681 // before its Layout function is called. | 733 // before its Layout function is called. |
| 682 CreateBrowserActionViews(); | 734 CreateActionViews(); |
| 683 } | 735 } |
| 684 } | 736 } |
| 685 | 737 |
| 686 // static | 738 // static |
| 687 int BrowserActionsContainer::IconWidth(bool include_padding) { | 739 int BrowserActionsContainer::IconWidth(bool include_padding) { |
| 688 static bool initialized = false; | 740 static bool initialized = false; |
| 689 static int icon_width = 0; | 741 static int icon_width = 0; |
| 690 if (!initialized) { | 742 if (!initialized) { |
| 691 initialized = true; | 743 initialized = true; |
| 692 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 744 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 713 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 765 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 714 DCHECK(browser_action_views_[i]->extension() != extension) << | 766 DCHECK(browser_action_views_[i]->extension() != extension) << |
| 715 "Asked to add a browser action view for an extension that already " | 767 "Asked to add a browser action view for an extension that already " |
| 716 "exists."; | 768 "exists."; |
| 717 } | 769 } |
| 718 #endif | 770 #endif |
| 719 if (chevron_) | 771 if (chevron_) |
| 720 chevron_->CloseMenu(); | 772 chevron_->CloseMenu(); |
| 721 | 773 |
| 722 // Add the new browser action to the vector and the view hierarchy. | 774 // Add the new browser action to the vector and the view hierarchy. |
| 723 BrowserActionView* view = | 775 BrowserActionView* view = new BrowserActionView( |
| 724 new BrowserActionView(extension, | 776 make_scoped_ptr(new ExtensionActionViewController( |
| 725 extensions::ExtensionActionManager::Get(profile_)-> | 777 extension, |
| 726 GetExtensionAction(*extension), | 778 browser_, |
| 727 browser_, | 779 extensions::ExtensionActionManager::Get(profile_)-> |
| 728 this); | 780 GetExtensionAction(*extension), |
| 781 NULL)), | |
| 782 BrowserActionView::TYPE_EXTENSION_ACTION, | |
| 783 browser_, | |
| 784 this); | |
| 729 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 785 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
| 730 AddChildViewAt(view, index); | 786 AddChildViewAt(view, index); |
| 731 | 787 |
| 732 // If we are still initializing the container, don't bother animating. | 788 // If we are still initializing the container, don't bother animating. |
| 733 if (!model_->extensions_initialized()) | 789 if (!model_->extensions_initialized()) |
| 734 return; | 790 return; |
| 735 | 791 |
| 736 // If this is just an upgrade, then don't worry about resizing. | 792 // If this is just an upgrade, then don't worry about resizing. |
| 737 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 793 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 738 IsBeingUpgraded(extension)) { | 794 IsBeingUpgraded(extension)) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 758 } | 814 } |
| 759 | 815 |
| 760 void BrowserActionsContainer::ToolbarExtensionRemoved( | 816 void BrowserActionsContainer::ToolbarExtensionRemoved( |
| 761 const Extension* extension) { | 817 const Extension* extension) { |
| 762 if (chevron_) | 818 if (chevron_) |
| 763 chevron_->CloseMenu(); | 819 chevron_->CloseMenu(); |
| 764 | 820 |
| 765 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 821 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 766 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 822 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 767 i != browser_action_views_.end(); ++i) { | 823 i != browser_action_views_.end(); ++i) { |
| 768 if ((*i)->extension() == extension) { | 824 if ((*i)->GetExtensionActionViewController()->extension() == extension) { |
| 769 delete *i; | 825 delete *i; |
| 770 browser_action_views_.erase(i); | 826 browser_action_views_.erase(i); |
| 771 | 827 |
| 772 // If the extension is being upgraded we don't want the bar to shrink | 828 // If the extension is being upgraded we don't want the bar to shrink |
| 773 // because the icon is just going to get re-added to the same location. | 829 // because the icon is just going to get re-added to the same location. |
| 774 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 830 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 775 IsBeingUpgraded(extension)) | 831 IsBeingUpgraded(extension)) |
| 776 return; | 832 return; |
| 777 | 833 |
| 778 if (browser_action_views_.size() > visible_actions) { | 834 if (browser_action_views_.size() > visible_actions) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 792 } | 848 } |
| 793 } | 849 } |
| 794 } | 850 } |
| 795 | 851 |
| 796 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, | 852 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, |
| 797 int index) { | 853 int index) { |
| 798 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 854 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
| 799 | 855 |
| 800 BrowserActionViews::iterator iter = browser_action_views_.begin(); | 856 BrowserActionViews::iterator iter = browser_action_views_.begin(); |
| 801 while (iter != browser_action_views_.end() && | 857 while (iter != browser_action_views_.end() && |
| 802 (*iter)->extension() != extension) { | 858 (*iter)->GetExtensionActionViewController()->extension() != extension) |
| 803 ++iter; | 859 ++iter; |
| 804 } | |
| 805 | 860 |
| 806 DCHECK(iter != browser_action_views_.end()); | 861 DCHECK(iter != browser_action_views_.end()); |
| 807 if (iter - browser_action_views_.begin() == index) | 862 if (iter - browser_action_views_.begin() == index) |
| 808 return; // Already in place. | 863 return; // Already in place. |
| 809 | 864 |
| 810 BrowserActionView* moved_view = *iter; | 865 BrowserActionView* moved_view = *iter; |
| 811 browser_action_views_.erase(iter); | 866 browser_action_views_.erase(iter); |
| 812 browser_action_views_.insert( | 867 browser_action_views_.insert( |
| 813 browser_action_views_.begin() + index, moved_view); | 868 browser_action_views_.begin() + index, moved_view); |
| 814 | 869 |
| 815 Layout(); | 870 Layout(); |
| 816 SchedulePaint(); | 871 SchedulePaint(); |
| 817 } | 872 } |
| 818 | 873 |
| 819 void BrowserActionsContainer::ToolbarExtensionUpdated( | 874 void BrowserActionsContainer::ToolbarExtensionUpdated( |
| 820 const Extension* extension) { | 875 const Extension* extension) { |
| 821 BrowserActionView* view = GetViewForExtension(extension); | 876 BrowserActionView* view = GetViewForExtension(extension); |
| 822 DCHECK(view); | 877 DCHECK(view); |
| 823 view->UpdateState(); | 878 view->UpdateState(); |
| 824 } | 879 } |
| 825 | 880 |
| 826 bool BrowserActionsContainer::ShowExtensionActionPopup( | 881 bool BrowserActionsContainer::ShowExtensionActionPopup( |
| 827 const Extension* extension, | 882 const Extension* extension, |
| 828 bool grant_active_tab) { | 883 bool grant_active_tab) { |
| 829 // Don't override another popup, and only show in the active window. | 884 // Don't override another popup, and only show in the active window. |
| 830 if (popup_owner_ || !browser_->window()->IsActive()) | 885 if (popup_owner_ || !browser_->window()->IsActive()) |
| 831 return false; | 886 return false; |
| 832 | 887 |
| 833 BrowserActionView* view = GetViewForExtension(extension); | 888 BrowserActionView* view = GetViewForExtension(extension); |
| 834 return view && view->view_controller()->ExecuteAction(ExtensionPopup::SHOW, | 889 return view && view->GetExtensionActionViewController()->ExecuteAction( |
| 835 grant_active_tab); | 890 ExtensionPopup::SHOW, grant_active_tab); |
| 836 } | 891 } |
| 837 | 892 |
| 838 void BrowserActionsContainer::ToolbarVisibleCountChanged() { | 893 void BrowserActionsContainer::ToolbarVisibleCountChanged() { |
| 839 if (GetPreferredWidth() != container_width_) | 894 if (GetPreferredWidth() != container_width_) |
| 840 Animate(gfx::Tween::EASE_OUT, GetIconCount()); | 895 Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
| 841 } | 896 } |
| 842 | 897 |
| 843 void BrowserActionsContainer::ToolbarHighlightModeChanged( | 898 void BrowserActionsContainer::ToolbarHighlightModeChanged( |
| 844 bool is_highlighting) { | 899 bool is_highlighting) { |
| 845 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 900 // The visual highlighting is done in OnPaint(). It's a bit of a pain that |
| 846 // we delete and recreate everything here, but given everything else going on | 901 // we delete and recreate everything here, but given everything else going on |
| 847 // (the lack of highlight, n more extensions appearing, etc), it's not worth | 902 // (the lack of highlight, n more extensions appearing, etc), it's not worth |
| 848 // the extra complexity to create and insert only the new extensions. | 903 // the extra complexity to create and insert only the new extensions. |
| 849 DeleteBrowserActionViews(); | 904 DeleteActionViews(); |
| 850 CreateBrowserActionViews(); | 905 CreateActionViews(); |
| 851 Animate(gfx::Tween::LINEAR, GetIconCount()); | 906 Animate(gfx::Tween::LINEAR, GetIconCount()); |
| 852 } | 907 } |
| 853 | 908 |
| 854 Browser* BrowserActionsContainer::GetBrowser() { | 909 Browser* BrowserActionsContainer::GetBrowser() { |
| 855 return browser_; | 910 return browser_; |
| 856 } | 911 } |
| 857 | 912 |
| 858 void BrowserActionsContainer::LoadImages() { | 913 void BrowserActionsContainer::LoadImages() { |
| 859 if (in_overflow_mode()) | 914 if (in_overflow_mode()) |
| 860 return; // Overflow mode has neither a chevron nor highlighting. | 915 return; // Overflow mode has neither a chevron nor highlighting. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 // Good time for some sanity checks: We should never try to display more | 1016 // Good time for some sanity checks: We should never try to display more |
| 962 // icons than we have, and we should always have a view per item in the model. | 1017 // icons than we have, and we should always have a view per item in the model. |
| 963 // (The only exception is if this is in initialization.) | 1018 // (The only exception is if this is in initialization.) |
| 964 if (initialized_) { | 1019 if (initialized_) { |
| 965 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); | 1020 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size()); |
| 966 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); | 1021 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size()); |
| 967 } | 1022 } |
| 968 | 1023 |
| 969 // The overflow displays any icons not shown by the main bar. | 1024 // The overflow displays any icons not shown by the main bar. |
| 970 return in_overflow_mode() ? | 1025 return in_overflow_mode() ? |
| 971 model_->toolbar_items().size() - absolute_model_visible_size : | 1026 model_->toolbar_items().size() - absolute_model_visible_size + |
| 1027 chrome_action_views_.size() : | |
| 972 absolute_model_visible_size; | 1028 absolute_model_visible_size; |
| 973 } | 1029 } |
| OLD | NEW |