OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/launcher/launcher_view.h" | 5 #include "ui/aura_shell/launcher/launcher_view.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura_shell/launcher/app_launcher_button.h" | 10 #include "ui/aura_shell/launcher/app_launcher_button.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 model_->RemoveObserver(this); | 223 model_->RemoveObserver(this); |
224 } | 224 } |
225 | 225 |
226 void LauncherView::Init() { | 226 void LauncherView::Init() { |
227 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 227 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
228 model_->AddObserver(this); | 228 model_->AddObserver(this); |
229 | 229 |
230 set_background( | 230 set_background( |
231 views::Background::CreateBackgroundPainter(true, new ShelfPainter())); | 231 views::Background::CreateBackgroundPainter(true, new ShelfPainter())); |
232 | 232 |
233 new_browser_button_ = new views::ImageButton(this); | 233 show_apps_button_ = new views::ImageButton(this); |
234 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | 234 show_apps_button_->SetImage( |
235 int new_browser_button_image_id = delegate ? | |
236 delegate->GetResourceIDForNewBrowserWindow() : | |
237 IDR_AURA_LAUNCHER_ICON_CHROME; | |
238 new_browser_button_->SetImage( | |
239 views::CustomButton::BS_NORMAL, | 235 views::CustomButton::BS_NORMAL, |
240 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap()); | 236 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); |
241 ConfigureChildView(new_browser_button_); | 237 show_apps_button_->SetImage( |
242 AddChildView(new_browser_button_); | 238 views::CustomButton::BS_HOT, |
| 239 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).ToSkBitmap()); |
| 240 show_apps_button_->SetImage( |
| 241 views::CustomButton::BS_PUSHED, |
| 242 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).ToSkBitmap()); |
| 243 ConfigureChildView(show_apps_button_); |
| 244 AddChildView(show_apps_button_); |
243 | 245 |
244 const LauncherItems& items(model_->items()); | 246 const LauncherItems& items(model_->items()); |
245 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 247 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
246 views::View* child = CreateViewForItem(*i); | 248 views::View* child = CreateViewForItem(*i); |
247 child->SetPaintToLayer(true); | 249 child->SetPaintToLayer(true); |
248 view_model_->Add(child, static_cast<int>(i - items.begin())); | 250 view_model_->Add(child, static_cast<int>(i - items.begin())); |
249 AddChildView(child); | 251 AddChildView(child); |
250 } | 252 } |
251 | 253 |
252 show_apps_button_ = new views::ImageButton(this); | 254 new_browser_button_ = new views::ImageButton(this); |
253 show_apps_button_->SetImage( | 255 new_browser_button_->SetImage( |
254 views::CustomButton::BS_NORMAL, | 256 views::CustomButton::BS_NORMAL, |
255 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); | 257 rb.GetImageNamed(IDR_AURA_LAUNCHER_NEW_BROWSER).ToSkBitmap()); |
256 show_apps_button_->SetImage( | 258 new_browser_button_->SetImage( |
257 views::CustomButton::BS_HOT, | 259 views::CustomButton::BS_HOT, |
258 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).ToSkBitmap()); | 260 rb.GetImageNamed(IDR_AURA_LAUNCHER_NEW_BROWSER_HOT).ToSkBitmap()); |
259 show_apps_button_->SetImage( | 261 new_browser_button_->SetImage( |
260 views::CustomButton::BS_PUSHED, | 262 views::CustomButton::BS_PUSHED, |
261 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).ToSkBitmap()); | 263 rb.GetImageNamed(IDR_AURA_LAUNCHER_NEW_BROWSER_PUSHED).ToSkBitmap()); |
262 ConfigureChildView(show_apps_button_); | 264 ConfigureChildView(new_browser_button_); |
263 AddChildView(show_apps_button_); | 265 AddChildView(new_browser_button_); |
264 | 266 |
265 overflow_button_ = new views::ImageButton(this); | 267 overflow_button_ = new views::ImageButton(this); |
266 overflow_button_->SetImage( | 268 overflow_button_->SetImage( |
267 views::CustomButton::BS_NORMAL, | 269 views::CustomButton::BS_NORMAL, |
268 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); | 270 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); |
269 overflow_button_->SetImage( | 271 overflow_button_->SetImage( |
270 views::CustomButton::BS_HOT, | 272 views::CustomButton::BS_HOT, |
271 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToSkBitmap()); | 273 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToSkBitmap()); |
272 overflow_button_->SetImage( | 274 overflow_button_->SetImage( |
273 views::CustomButton::BS_PUSHED, | 275 views::CustomButton::BS_PUSHED, |
274 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToSkBitmap()); | 276 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToSkBitmap()); |
275 ConfigureChildView(overflow_button_); | 277 ConfigureChildView(overflow_button_); |
276 AddChildView(overflow_button_); | 278 AddChildView(overflow_button_); |
277 | 279 |
278 // We'll layout when our bounds change. | 280 // We'll layout when our bounds change. |
279 } | 281 } |
280 | 282 |
281 void LauncherView::LayoutToIdealBounds() { | 283 void LauncherView::LayoutToIdealBounds() { |
282 IdealBounds ideal_bounds; | 284 IdealBounds ideal_bounds; |
283 CalculateIdealBounds(&ideal_bounds); | 285 CalculateIdealBounds(&ideal_bounds); |
| 286 show_apps_button_->SetBoundsRect(ideal_bounds.show_apps_bounds); |
284 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); | 287 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); |
285 show_apps_button_->SetBoundsRect(ideal_bounds.show_apps_bounds); | |
286 ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 288 ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
287 } | 289 } |
288 | 290 |
289 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { | 291 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
290 int available_width = width(); | 292 int available_width = width(); |
291 if (!available_width) | 293 if (!available_width) |
292 return; | 294 return; |
293 | 295 |
294 // new_browser_button first. | 296 // show_apps_button_ first. |
295 int x = kLeadingInset; | 297 int x = kLeadingInset; |
296 gfx::Size pref = new_browser_button_->GetPreferredSize(); | 298 gfx::Size pref = show_apps_button_->GetPreferredSize(); |
297 bounds->new_browser_bounds = gfx::Rect( | 299 bounds->show_apps_bounds = gfx::Rect( |
298 x, (kPreferredHeight - pref.height()) / 2, pref.width(), pref.height()); | 300 x, (kPreferredHeight - pref.height()) / 2, pref.width(), pref.height()); |
299 x += bounds->new_browser_bounds.width() + kHorizontalPadding; | 301 x += bounds->show_apps_bounds.width() + kHorizontalPadding; |
| 302 // TODO: remove when we get better images. |
| 303 x -= 6; |
300 | 304 |
301 // Then launcher buttons. | 305 // Then launcher buttons. |
302 for (int i = 0; i < view_model_->view_size(); ++i) { | 306 for (int i = 0; i < view_model_->view_size(); ++i) { |
303 pref = view_model_->view_at(i)->GetPreferredSize(); | 307 pref = view_model_->view_at(i)->GetPreferredSize(); |
304 view_model_->set_ideal_bounds(i, gfx::Rect( | 308 view_model_->set_ideal_bounds(i, gfx::Rect( |
305 x, (kPreferredHeight - pref.height()) / 2, pref.width(), | 309 x, (kPreferredHeight - pref.height()) / 2, pref.width(), |
306 pref.height())); | 310 pref.height())); |
307 x += pref.width() + kHorizontalPadding; | 311 x += pref.width() + kHorizontalPadding; |
308 } | 312 } |
309 | 313 |
310 // Show apps button and overflow button. | 314 // new_browser_button_ and overflow button. |
311 bounds->show_apps_bounds.set_size(show_apps_button_->GetPreferredSize()); | 315 bounds->new_browser_bounds.set_size(new_browser_button_->GetPreferredSize()); |
312 bounds->overflow_bounds.set_size(overflow_button_->GetPreferredSize()); | 316 bounds->overflow_bounds.set_size(overflow_button_->GetPreferredSize()); |
313 int last_visible_index = DetermineLastVisibleIndex( | 317 int last_visible_index = DetermineLastVisibleIndex( |
314 available_width - kLeadingInset - bounds->show_apps_bounds.width() - | 318 available_width - kLeadingInset - bounds->new_browser_bounds.width() - |
315 kHorizontalPadding - bounds->overflow_bounds.width() - | 319 kHorizontalPadding - bounds->overflow_bounds.width() - |
316 kHorizontalPadding); | 320 kHorizontalPadding); |
317 bool show_overflow = (last_visible_index + 1 != view_model_->view_size()); | 321 bool show_overflow = (last_visible_index + 1 != view_model_->view_size()); |
318 if (overflow_button_->visible() != show_overflow) { | 322 if (overflow_button_->visible() != show_overflow) { |
319 // Only change visibility of the views if the visibility of the overflow | 323 // Only change visibility of the views if the visibility of the overflow |
320 // button changes. Otherwise we'll effect the insertion animation, which | 324 // button changes. Otherwise we'll effect the insertion animation, which |
321 // changes the visibility. | 325 // changes the visibility. |
322 for (int i = 0; i <= last_visible_index; ++i) | 326 for (int i = 0; i <= last_visible_index; ++i) |
323 view_model_->view_at(i)->SetVisible(true); | 327 view_model_->view_at(i)->SetVisible(true); |
324 for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) | 328 for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) |
325 view_model_->view_at(i)->SetVisible(false); | 329 view_model_->view_at(i)->SetVisible(false); |
326 } | 330 } |
327 | 331 |
328 overflow_button_->SetVisible(show_overflow); | 332 overflow_button_->SetVisible(show_overflow); |
329 if (show_overflow) { | 333 if (show_overflow) { |
330 DCHECK_NE(0, view_model_->view_size()); | 334 DCHECK_NE(0, view_model_->view_size()); |
331 x = view_model_->ideal_bounds(last_visible_index).right() + | 335 x = view_model_->ideal_bounds(last_visible_index).right() + |
332 kHorizontalPadding; | 336 kHorizontalPadding; |
333 bounds->overflow_bounds.set_x(x); | 337 bounds->overflow_bounds.set_x(x); |
334 bounds->overflow_bounds.set_y( | 338 bounds->overflow_bounds.set_y( |
335 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); | 339 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); |
336 x = bounds->overflow_bounds.right() + kHorizontalPadding; | 340 x = bounds->overflow_bounds.right() + kHorizontalPadding; |
337 } | 341 } |
338 // TODO(sky): -6 is a hack, remove when we get better images. | 342 bounds->new_browser_bounds.set_x(x); |
339 bounds->show_apps_bounds.set_x(x - 6); | 343 bounds->new_browser_bounds.set_y( |
340 bounds->show_apps_bounds.set_y( | 344 (kPreferredHeight - bounds->new_browser_bounds.height()) / 2); |
341 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); | |
342 } | 345 } |
343 | 346 |
344 int LauncherView::DetermineLastVisibleIndex(int max_x) { | 347 int LauncherView::DetermineLastVisibleIndex(int max_x) { |
345 int index = view_model_->view_size() - 1; | 348 int index = view_model_->view_size() - 1; |
346 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) | 349 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) |
347 index--; | 350 index--; |
348 return index; | 351 return index; |
349 } | 352 } |
350 | 353 |
351 void LauncherView::AnimateToIdealBounds() { | 354 void LauncherView::AnimateToIdealBounds() { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 if (!was_dragging) | 494 if (!was_dragging) |
492 return; | 495 return; |
493 | 496 |
494 view_model_->Move(view_model_->GetIndexOfView(drag_view), start_drag_index_); | 497 view_model_->Move(view_model_->GetIndexOfView(drag_view), start_drag_index_); |
495 AnimateToIdealBounds(); | 498 AnimateToIdealBounds(); |
496 } | 499 } |
497 | 500 |
498 gfx::Size LauncherView::GetPreferredSize() { | 501 gfx::Size LauncherView::GetPreferredSize() { |
499 IdealBounds ideal_bounds; | 502 IdealBounds ideal_bounds; |
500 CalculateIdealBounds(&ideal_bounds); | 503 CalculateIdealBounds(&ideal_bounds); |
501 return gfx::Size(ideal_bounds.show_apps_bounds.right() + kLeadingInset, | 504 return gfx::Size(ideal_bounds.new_browser_bounds.right() + kLeadingInset, |
502 kPreferredHeight); | 505 kPreferredHeight); |
503 } | 506 } |
504 | 507 |
505 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 508 void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
506 LayoutToIdealBounds(); | 509 LayoutToIdealBounds(); |
507 } | 510 } |
508 | 511 |
509 void LauncherView::LauncherItemAdded(int model_index) { | 512 void LauncherView::LauncherItemAdded(int model_index) { |
510 CancelDrag(NULL); | 513 CancelDrag(NULL); |
511 | 514 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 } else { | 606 } else { |
604 int view_index = view_model_->GetIndexOfView(sender); | 607 int view_index = view_model_->GetIndexOfView(sender); |
605 // May be -1 while in the process of animating closed. | 608 // May be -1 while in the process of animating closed. |
606 if (view_index != -1) | 609 if (view_index != -1) |
607 delegate->LauncherItemClicked(model_->items()[view_index]); | 610 delegate->LauncherItemClicked(model_->items()[view_index]); |
608 } | 611 } |
609 } | 612 } |
610 | 613 |
611 } // namespace internal | 614 } // namespace internal |
612 } // namespace aura_shell | 615 } // namespace aura_shell |
OLD | NEW |