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