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/launcher/launcher_view.h" | 5 #include "ash/launcher/launcher_view.h" |
6 | 6 |
7 #include "ash/launcher/launcher_button.h" | 7 #include "ash/launcher/launcher_button.h" |
8 #include "ash/launcher/launcher_delegate.h" | 8 #include "ash/launcher/launcher_delegate.h" |
9 #include "ash/launcher/launcher_icon_observer.h" | |
9 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
10 #include "ash/launcher/tabbed_launcher_button.h" | 11 #include "ash/launcher/tabbed_launcher_button.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
12 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
13 #include "base/auto_reset.h" | 14 #include "base/auto_reset.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
16 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
18 #include "ui/base/animation/animation.h" | 19 #include "ui/base/animation/animation.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 return NULL; | 249 return NULL; |
249 | 250 |
250 return static_cast<LauncherButton*>( | 251 return static_cast<LauncherButton*>( |
251 launcher_view_->view_model_->view_at(index)); | 252 launcher_view_->view_model_->view_at(index)); |
252 } | 253 } |
253 | 254 |
254 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) | 255 LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) |
255 : model_(model), | 256 : model_(model), |
256 delegate_(delegate), | 257 delegate_(delegate), |
257 view_model_(new views::ViewModel), | 258 view_model_(new views::ViewModel), |
259 last_visible_index_(-1), | |
258 overflow_button_(NULL), | 260 overflow_button_(NULL), |
259 dragging_(NULL), | 261 dragging_(NULL), |
260 drag_view_(NULL), | 262 drag_view_(NULL), |
261 drag_offset_(0), | 263 drag_offset_(0), |
262 start_drag_index_(-1), | 264 start_drag_index_(-1), |
263 context_menu_id_(0) { | 265 context_menu_id_(0) { |
264 DCHECK(model_); | 266 DCHECK(model_); |
265 bounds_animator_.reset(new views::BoundsAnimator(this)); | 267 bounds_animator_.reset(new views::BoundsAnimator(this)); |
266 set_context_menu_controller(this); | 268 set_context_menu_controller(this); |
267 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); | 269 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); |
(...skipping 30 matching lines...) Expand all Loading... | |
298 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); | 300 l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME)); |
299 overflow_button_->set_context_menu_controller(this); | 301 overflow_button_->set_context_menu_controller(this); |
300 ConfigureChildView(overflow_button_); | 302 ConfigureChildView(overflow_button_); |
301 AddChildView(overflow_button_); | 303 AddChildView(overflow_button_); |
302 | 304 |
303 // We'll layout when our bounds change. | 305 // We'll layout when our bounds change. |
304 } | 306 } |
305 | 307 |
306 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { | 308 gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { |
307 int index = model_->ItemIndexByID(id); | 309 int index = model_->ItemIndexByID(id); |
308 if (index == -1 || !view_model_->view_at(index)->visible()) | 310 if (index == -1 || index > last_visible_index_) |
309 return gfx::Rect(); | 311 return gfx::Rect(); |
310 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); | 312 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); |
311 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); | 313 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); |
312 LauncherButton* button = | 314 LauncherButton* button = |
313 static_cast<LauncherButton*>(view_model_->view_at(index)); | 315 static_cast<LauncherButton*>(view_model_->view_at(index)); |
314 gfx::Rect icon_bounds = button->GetIconBounds(); | 316 gfx::Rect icon_bounds = button->GetIconBounds(); |
315 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), | 317 return gfx::Rect(ideal_bounds.x() + icon_bounds.x(), |
316 ideal_bounds.y() + icon_bounds.y(), | 318 ideal_bounds.y() + icon_bounds.y(), |
317 icon_bounds.width(), icon_bounds.height()); | 319 icon_bounds.width(), icon_bounds.height()); |
318 } | 320 } |
(...skipping 21 matching lines...) Expand all Loading... | |
340 | 342 |
341 View* LauncherView::GetFocusTraversableParentView() { | 343 View* LauncherView::GetFocusTraversableParentView() { |
342 return this; | 344 return this; |
343 } | 345 } |
344 | 346 |
345 void LauncherView::LayoutToIdealBounds() { | 347 void LauncherView::LayoutToIdealBounds() { |
346 IdealBounds ideal_bounds; | 348 IdealBounds ideal_bounds; |
347 CalculateIdealBounds(&ideal_bounds); | 349 CalculateIdealBounds(&ideal_bounds); |
348 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 350 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
349 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 351 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
352 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | |
353 OnLauncherIconPositionsChanged()); | |
350 } | 354 } |
351 | 355 |
352 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { | 356 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
353 int available_width = width(); | 357 int available_width = width(); |
354 if (!available_width) | 358 if (!available_width) |
355 return; | 359 return; |
356 | 360 |
357 int x = kLeadingInset; | 361 int x = kLeadingInset; |
358 for (int i = 0; i < view_model_->view_size(); ++i) { | 362 for (int i = 0; i < view_model_->view_size(); ++i) { |
359 gfx::Size pref(kButtonWidth, kButtonHeight); | 363 gfx::Size pref(kButtonWidth, kButtonHeight); |
360 view_model_->set_ideal_bounds(i, gfx::Rect( | 364 view_model_->set_ideal_bounds(i, gfx::Rect( |
361 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), | 365 x, (kLauncherPreferredHeight - pref.height()) / 2, pref.width(), |
362 pref.height())); | 366 pref.height())); |
363 x += pref.width() + kButtonSpacing; | 367 x += pref.width() + kButtonSpacing; |
364 } | 368 } |
365 | 369 |
366 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); | 370 bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); |
367 int last_visible_index = DetermineLastVisibleIndex( | 371 last_visible_index_ = DetermineLastVisibleIndex( |
368 available_width - kLeadingInset - bounds->overflow_bounds.width() - | 372 available_width - kLeadingInset - bounds->overflow_bounds.width() - |
369 kButtonSpacing - kButtonWidth); | 373 kButtonSpacing - kButtonWidth); |
370 bool show_overflow = | 374 bool show_overflow = |
371 (last_visible_index + 1 != view_model_->view_size()); | 375 (last_visible_index_ + 1 != view_model_->view_size()); |
372 int app_list_index = view_model_->view_size() - 1; | 376 int app_list_index = view_model_->view_size() - 1; |
373 if (overflow_button_->visible() != show_overflow) { | 377 if (overflow_button_->visible() != show_overflow) { |
374 // Only change visibility of the views if the visibility of the overflow | 378 // Only change visibility of the views if the visibility of the overflow |
375 // button changes. Otherwise we'll effect the insertion animation, which | 379 // button changes. Otherwise we'll effect the insertion animation, which |
376 // changes the visibility. | 380 // changes the visibility. |
377 for (int i = 0; i <= last_visible_index; ++i) | 381 for (int i = 0; i <= last_visible_index_; ++i) |
378 view_model_->view_at(i)->SetVisible(true); | 382 view_model_->view_at(i)->SetVisible(true); |
379 for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) { | 383 for (int i = last_visible_index_ + 1; i < view_model_->view_size(); ++i) { |
380 if (i != app_list_index) | 384 if (i != app_list_index) |
381 view_model_->view_at(i)->SetVisible(false); | 385 view_model_->view_at(i)->SetVisible(false); |
382 } | 386 } |
383 } | 387 } |
384 overflow_button_->SetVisible(show_overflow); | 388 overflow_button_->SetVisible(show_overflow); |
385 if (show_overflow) { | 389 if (show_overflow) { |
386 DCHECK_NE(0, view_model_->view_size()); | 390 DCHECK_NE(0, view_model_->view_size()); |
387 // We always want the app list visible. | 391 // We always want the app list visible. |
388 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); | 392 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); |
389 x = last_visible_index == -1 ? | 393 x = last_visible_index_ == -1 ? |
390 kLeadingInset : view_model_->ideal_bounds(last_visible_index).right(); | 394 kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); |
391 app_list_bounds.set_x(x); | 395 app_list_bounds.set_x(x); |
392 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); | 396 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); |
393 x = app_list_bounds.right() + kButtonSpacing; | 397 x = app_list_bounds.right() + kButtonSpacing; |
394 bounds->overflow_bounds.set_x(x); | 398 bounds->overflow_bounds.set_x(x); |
395 bounds->overflow_bounds.set_y( | 399 bounds->overflow_bounds.set_y( |
396 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); | 400 (kLauncherPreferredHeight - bounds->overflow_bounds.height()) / 2); |
397 } | 401 } |
398 } | 402 } |
399 | 403 |
400 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 404 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
401 int index = view_model_->view_size() - 1; | 405 int index = view_model_->view_size() - 1; |
402 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) | 406 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) |
403 index--; | 407 index--; |
404 return index; | 408 return index; |
405 } | 409 } |
406 | 410 |
411 void LauncherView::AddIconObserver(LauncherIconObserver* observer) { | |
412 observers_.AddObserver(observer); | |
413 } | |
414 | |
415 void LauncherView::RemoveIconObserver(LauncherIconObserver* observer) { | |
416 observers_.RemoveObserver(observer); | |
417 } | |
418 | |
407 void LauncherView::AnimateToIdealBounds() { | 419 void LauncherView::AnimateToIdealBounds() { |
408 IdealBounds ideal_bounds; | 420 IdealBounds ideal_bounds; |
409 CalculateIdealBounds(&ideal_bounds); | 421 CalculateIdealBounds(&ideal_bounds); |
422 // We report ideal bounds in GetScreenBoundsOfItemIconForWindow; | |
423 // we know them already here, so we report the change before animation. | |
424 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | |
425 OnLauncherIconPositionsChanged()); | |
Dmitry Lomov (no reviews)
2012/04/13 06:14:14
This change is needed for Add test to work. I am n
sky
2012/04/13 17:32:15
This isn't the right place either. The notificatio
Dmitry Lomov (no reviews)
2012/04/13 17:41:04
No not really - we need to send notifiactions *aft
| |
410 for (int i = 0; i < view_model_->view_size(); ++i) { | 426 for (int i = 0; i < view_model_->view_size(); ++i) { |
411 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 427 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
412 view_model_->ideal_bounds(i)); | 428 view_model_->ideal_bounds(i)); |
413 } | 429 } |
414 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 430 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
415 } | 431 } |
416 | 432 |
417 views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { | 433 views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { |
418 views::View* view = NULL; | 434 views::View* view = NULL; |
419 switch (item.type) { | 435 switch (item.type) { |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
888 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 904 source->GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
889 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) | 905 views::MenuItemView::TOPLEFT, 0) == views::MenuRunner::MENU_DELETED) |
890 return; | 906 return; |
891 | 907 |
892 Shell::GetInstance()->UpdateShelfVisibility(); | 908 Shell::GetInstance()->UpdateShelfVisibility(); |
893 #endif | 909 #endif |
894 } | 910 } |
895 | 911 |
896 } // namespace internal | 912 } // namespace internal |
897 } // namespace ash | 913 } // namespace ash |
OLD | NEW |