| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorDisabler); | 134 DISALLOW_COPY_AND_ASSIGN(BoundsAnimatorDisabler); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to | 137 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to |
| 138 // our requirements. | 138 // our requirements. |
| 139 class ShelfMenuModelAdapter : public views::MenuModelAdapter { | 139 class ShelfMenuModelAdapter : public views::MenuModelAdapter { |
| 140 public: | 140 public: |
| 141 explicit ShelfMenuModelAdapter(ShelfMenuModel* menu_model); | 141 explicit ShelfMenuModelAdapter(ShelfMenuModel* menu_model); |
| 142 | 142 |
| 143 // views::MenuModelAdapter: | 143 // views::MenuModelAdapter: |
| 144 virtual const gfx::FontList* GetLabelFontList(int command_id) const override; | 144 const gfx::FontList* GetLabelFontList(int command_id) const override; |
| 145 virtual bool IsCommandEnabled(int id) const override; | 145 bool IsCommandEnabled(int id) const override; |
| 146 virtual void GetHorizontalIconMargins(int id, | 146 void GetHorizontalIconMargins(int id, |
| 147 int icon_size, | 147 int icon_size, |
| 148 int* left_margin, | 148 int* left_margin, |
| 149 int* right_margin) const override; | 149 int* right_margin) const override; |
| 150 virtual bool GetForegroundColor(int command_id, | 150 bool GetForegroundColor(int command_id, |
| 151 bool is_hovered, | 151 bool is_hovered, |
| 152 SkColor* override_color) const override; | 152 SkColor* override_color) const override; |
| 153 virtual bool GetBackgroundColor(int command_id, | 153 bool GetBackgroundColor(int command_id, |
| 154 bool is_hovered, | 154 bool is_hovered, |
| 155 SkColor* override_color) const override; | 155 SkColor* override_color) const override; |
| 156 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) override; | 156 int GetMaxWidthForMenu(views::MenuItemView* menu) override; |
| 157 virtual bool ShouldReserveSpaceForSubmenuIndicator() const override; | 157 bool ShouldReserveSpaceForSubmenuIndicator() const override; |
| 158 | 158 |
| 159 private: | 159 private: |
| 160 ShelfMenuModel* menu_model_; | 160 ShelfMenuModel* menu_model_; |
| 161 | 161 |
| 162 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelAdapter); | 162 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelAdapter); |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model) | 165 ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model) |
| 166 : MenuModelAdapter(menu_model), | 166 : MenuModelAdapter(menu_model), |
| 167 menu_model_(menu_model) { | 167 menu_model_(menu_model) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 | 220 |
| 221 // Custom FocusSearch used to navigate the shelf in the order items are in | 221 // Custom FocusSearch used to navigate the shelf in the order items are in |
| 222 // the ViewModel. | 222 // the ViewModel. |
| 223 class ShelfFocusSearch : public views::FocusSearch { | 223 class ShelfFocusSearch : public views::FocusSearch { |
| 224 public: | 224 public: |
| 225 explicit ShelfFocusSearch(views::ViewModel* view_model) | 225 explicit ShelfFocusSearch(views::ViewModel* view_model) |
| 226 : FocusSearch(NULL, true, true), | 226 : FocusSearch(NULL, true, true), |
| 227 view_model_(view_model) {} | 227 view_model_(view_model) {} |
| 228 virtual ~ShelfFocusSearch() {} | 228 ~ShelfFocusSearch() override {} |
| 229 | 229 |
| 230 // views::FocusSearch overrides: | 230 // views::FocusSearch overrides: |
| 231 virtual View* FindNextFocusableView( | 231 View* FindNextFocusableView(View* starting_view, |
| 232 View* starting_view, | 232 bool reverse, |
| 233 bool reverse, | 233 Direction direction, |
| 234 Direction direction, | 234 bool check_starting_view, |
| 235 bool check_starting_view, | 235 views::FocusTraversable** focus_traversable, |
| 236 views::FocusTraversable** focus_traversable, | 236 View** focus_traversable_view) override { |
| 237 View** focus_traversable_view) override { | |
| 238 int index = view_model_->GetIndexOfView(starting_view); | 237 int index = view_model_->GetIndexOfView(starting_view); |
| 239 if (index == -1) | 238 if (index == -1) |
| 240 return view_model_->view_at(0); | 239 return view_model_->view_at(0); |
| 241 | 240 |
| 242 if (reverse) { | 241 if (reverse) { |
| 243 --index; | 242 --index; |
| 244 if (index < 0) | 243 if (index < 0) |
| 245 index = view_model_->view_size() - 1; | 244 index = view_model_->view_size() - 1; |
| 246 } else { | 245 } else { |
| 247 ++index; | 246 ++index; |
| 248 if (index >= view_model_->view_size()) | 247 if (index >= view_model_->view_size()) |
| 249 index = 0; | 248 index = 0; |
| 250 } | 249 } |
| 251 return view_model_->view_at(index); | 250 return view_model_->view_at(index); |
| 252 } | 251 } |
| 253 | 252 |
| 254 private: | 253 private: |
| 255 views::ViewModel* view_model_; | 254 views::ViewModel* view_model_; |
| 256 | 255 |
| 257 DISALLOW_COPY_AND_ASSIGN(ShelfFocusSearch); | 256 DISALLOW_COPY_AND_ASSIGN(ShelfFocusSearch); |
| 258 }; | 257 }; |
| 259 | 258 |
| 260 // AnimationDelegate used when inserting a new item. This steadily increases the | 259 // AnimationDelegate used when inserting a new item. This steadily increases the |
| 261 // opacity of the layer as the animation progress. | 260 // opacity of the layer as the animation progress. |
| 262 class FadeInAnimationDelegate : public gfx::AnimationDelegate { | 261 class FadeInAnimationDelegate : public gfx::AnimationDelegate { |
| 263 public: | 262 public: |
| 264 explicit FadeInAnimationDelegate(views::View* view) : view_(view) {} | 263 explicit FadeInAnimationDelegate(views::View* view) : view_(view) {} |
| 265 virtual ~FadeInAnimationDelegate() {} | 264 ~FadeInAnimationDelegate() override {} |
| 266 | 265 |
| 267 // AnimationDelegate overrides: | 266 // AnimationDelegate overrides: |
| 268 virtual void AnimationProgressed(const Animation* animation) override { | 267 void AnimationProgressed(const Animation* animation) override { |
| 269 view_->layer()->SetOpacity(animation->GetCurrentValue()); | 268 view_->layer()->SetOpacity(animation->GetCurrentValue()); |
| 270 view_->layer()->ScheduleDraw(); | 269 view_->layer()->ScheduleDraw(); |
| 271 } | 270 } |
| 272 virtual void AnimationEnded(const Animation* animation) override { | 271 void AnimationEnded(const Animation* animation) override { |
| 273 view_->layer()->SetOpacity(1.0f); | 272 view_->layer()->SetOpacity(1.0f); |
| 274 view_->layer()->ScheduleDraw(); | 273 view_->layer()->ScheduleDraw(); |
| 275 } | 274 } |
| 276 virtual void AnimationCanceled(const Animation* animation) override { | 275 void AnimationCanceled(const Animation* animation) override { |
| 277 view_->layer()->SetOpacity(1.0f); | 276 view_->layer()->SetOpacity(1.0f); |
| 278 view_->layer()->ScheduleDraw(); | 277 view_->layer()->ScheduleDraw(); |
| 279 } | 278 } |
| 280 | 279 |
| 281 private: | 280 private: |
| 282 views::View* view_; | 281 views::View* view_; |
| 283 | 282 |
| 284 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); | 283 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); |
| 285 }; | 284 }; |
| 286 | 285 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 311 | 310 |
| 312 } // namespace | 311 } // namespace |
| 313 | 312 |
| 314 // AnimationDelegate used when deleting an item. This steadily decreased the | 313 // AnimationDelegate used when deleting an item. This steadily decreased the |
| 315 // opacity of the layer as the animation progress. | 314 // opacity of the layer as the animation progress. |
| 316 class ShelfView::FadeOutAnimationDelegate : public gfx::AnimationDelegate { | 315 class ShelfView::FadeOutAnimationDelegate : public gfx::AnimationDelegate { |
| 317 public: | 316 public: |
| 318 FadeOutAnimationDelegate(ShelfView* host, views::View* view) | 317 FadeOutAnimationDelegate(ShelfView* host, views::View* view) |
| 319 : shelf_view_(host), | 318 : shelf_view_(host), |
| 320 view_(view) {} | 319 view_(view) {} |
| 321 virtual ~FadeOutAnimationDelegate() {} | 320 ~FadeOutAnimationDelegate() override {} |
| 322 | 321 |
| 323 // AnimationDelegate overrides: | 322 // AnimationDelegate overrides: |
| 324 virtual void AnimationProgressed(const Animation* animation) override { | 323 void AnimationProgressed(const Animation* animation) override { |
| 325 view_->layer()->SetOpacity(1 - animation->GetCurrentValue()); | 324 view_->layer()->SetOpacity(1 - animation->GetCurrentValue()); |
| 326 view_->layer()->ScheduleDraw(); | 325 view_->layer()->ScheduleDraw(); |
| 327 } | 326 } |
| 328 virtual void AnimationEnded(const Animation* animation) override { | 327 void AnimationEnded(const Animation* animation) override { |
| 329 shelf_view_->OnFadeOutAnimationEnded(); | 328 shelf_view_->OnFadeOutAnimationEnded(); |
| 330 } | 329 } |
| 331 virtual void AnimationCanceled(const Animation* animation) override { | 330 void AnimationCanceled(const Animation* animation) override {} |
| 332 } | |
| 333 | 331 |
| 334 private: | 332 private: |
| 335 ShelfView* shelf_view_; | 333 ShelfView* shelf_view_; |
| 336 scoped_ptr<views::View> view_; | 334 scoped_ptr<views::View> view_; |
| 337 | 335 |
| 338 DISALLOW_COPY_AND_ASSIGN(FadeOutAnimationDelegate); | 336 DISALLOW_COPY_AND_ASSIGN(FadeOutAnimationDelegate); |
| 339 }; | 337 }; |
| 340 | 338 |
| 341 // AnimationDelegate used to trigger fading an element in. When an item is | 339 // AnimationDelegate used to trigger fading an element in. When an item is |
| 342 // inserted this delegate is attached to the animation that expands the size of | 340 // inserted this delegate is attached to the animation that expands the size of |
| 343 // the item. When done it kicks off another animation to fade the item in. | 341 // the item. When done it kicks off another animation to fade the item in. |
| 344 class ShelfView::StartFadeAnimationDelegate : public gfx::AnimationDelegate { | 342 class ShelfView::StartFadeAnimationDelegate : public gfx::AnimationDelegate { |
| 345 public: | 343 public: |
| 346 StartFadeAnimationDelegate(ShelfView* host, | 344 StartFadeAnimationDelegate(ShelfView* host, |
| 347 views::View* view) | 345 views::View* view) |
| 348 : shelf_view_(host), | 346 : shelf_view_(host), |
| 349 view_(view) {} | 347 view_(view) {} |
| 350 virtual ~StartFadeAnimationDelegate() {} | 348 ~StartFadeAnimationDelegate() override {} |
| 351 | 349 |
| 352 // AnimationDelegate overrides: | 350 // AnimationDelegate overrides: |
| 353 virtual void AnimationEnded(const Animation* animation) override { | 351 void AnimationEnded(const Animation* animation) override { |
| 354 shelf_view_->FadeIn(view_); | 352 shelf_view_->FadeIn(view_); |
| 355 } | 353 } |
| 356 virtual void AnimationCanceled(const Animation* animation) override { | 354 void AnimationCanceled(const Animation* animation) override { |
| 357 view_->layer()->SetOpacity(1.0f); | 355 view_->layer()->SetOpacity(1.0f); |
| 358 } | 356 } |
| 359 | 357 |
| 360 private: | 358 private: |
| 361 ShelfView* shelf_view_; | 359 ShelfView* shelf_view_; |
| 362 views::View* view_; | 360 views::View* view_; |
| 363 | 361 |
| 364 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); | 362 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); |
| 365 }; | 363 }; |
| 366 | 364 |
| (...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 distance = bounds.x() - coordinate.x(); | 1925 distance = bounds.x() - coordinate.x(); |
| 1928 break; | 1926 break; |
| 1929 case SHELF_ALIGNMENT_TOP: | 1927 case SHELF_ALIGNMENT_TOP: |
| 1930 distance = coordinate.y() - bounds.bottom(); | 1928 distance = coordinate.y() - bounds.bottom(); |
| 1931 break; | 1929 break; |
| 1932 } | 1930 } |
| 1933 return distance > 0 ? distance : 0; | 1931 return distance > 0 ? distance : 0; |
| 1934 } | 1932 } |
| 1935 | 1933 |
| 1936 } // namespace ash | 1934 } // namespace ash |
| OLD | NEW |