Index: ash/app_list/app_list_view.cc |
diff --git a/ash/app_list/app_list_view.cc b/ash/app_list/app_list_view.cc |
index 9aa341085838ab3703a66c724e08695cf47ae6e3..c68312ef6894a4c4780a309040b52b4a6b02ede0 100644 |
--- a/ash/app_list/app_list_view.cc |
+++ b/ash/app_list/app_list_view.cc |
@@ -4,22 +4,33 @@ |
#include "ash/app_list/app_list_view.h" |
-#include "ash/app_list/app_list_groups_view.h" |
#include "ash/app_list/app_list_item_view.h" |
#include "ash/app_list/app_list_model.h" |
+#include "ash/app_list/app_list_model_view.h" |
#include "ash/app_list/app_list_view_delegate.h" |
#include "ash/shell.h" |
-#include "ui/views/layout/fill_layout.h" |
+#include "ui/gfx/screen.h" |
+#include "ui/views/background.h" |
#include "ui/views/widget/widget.h" |
namespace ash { |
+namespace { |
+ |
+// Margins in pixels from work area edges. |
+const int kMargin = 50; |
+ |
+// 0.4 black |
+const SkColor kBackgroundColor = SkColorSetARGB(0x66, 0, 0, 0); |
+ |
+} // namespace |
+ |
AppListView::AppListView( |
- AppListModel* model, |
AppListViewDelegate* delegate, |
const gfx::Rect& bounds) |
- : model_(model), |
- delegate_(delegate) { |
+ : delegate_(delegate), |
+ model_view_(NULL) { |
+ set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
Init(bounds); |
} |
@@ -32,13 +43,11 @@ void AppListView::Close() { |
} |
void AppListView::Init(const gfx::Rect& bounds) { |
- SetLayoutManager(new views::FillLayout); |
- AppListGroupsView* groups_view = new AppListGroupsView(model_.get(), this); |
- AddChildView(groups_view); |
+ model_view_ = new AppListModelView(this); |
+ AddChildView(model_view_); |
views::Widget::InitParams widget_params( |
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
- widget_params.bounds = bounds; |
widget_params.delegate = this; |
widget_params.keep_on_top = true; |
widget_params.transparent = true; |
@@ -46,9 +55,41 @@ void AppListView::Init(const gfx::Rect& bounds) { |
views::Widget* widget = new views::Widget; |
widget->Init(widget_params); |
widget->SetContentsView(this); |
+ widget->SetBounds(bounds); |
+ |
+ UpdateModel(); |
+} |
+ |
+void AppListView::UpdateModel() { |
+ if (delegate_.get()) { |
+ scoped_ptr<AppListModel> new_model(new AppListModel); |
+ delegate_->BuildAppListModel(std::string(), new_model.get()); |
+ model_view_->SetModel(new_model.get()); |
+ model_.reset(new_model.release()); |
+ } |
+} |
+ |
+views::View* AppListView::GetInitiallyFocusedView() { |
+ return model_view_; |
+} |
+ |
+void AppListView::Layout() { |
+ gfx::Rect rect(GetContentsBounds()); |
+ if (rect.IsEmpty()) |
+ return; |
- if (groups_view->GetFocusedTile()) |
- groups_view->GetFocusedTile()->RequestFocus(); |
+ // Gets work area rect, which is in screen coordinates. |
+ gfx::Rect workarea = gfx::Screen::GetMonitorWorkAreaNearestWindow( |
+ GetWidget()->GetNativeView()); |
+ |
+ // Converts |workarea| into view's coordinates. |
+ gfx::Point origin(workarea.origin()); |
+ views::View::ConvertPointFromScreen(this, &origin); |
+ workarea.Offset(-origin.x(), -origin.y()); |
+ |
+ rect = rect.Intersect(workarea); |
+ rect.Inset(kMargin, kMargin); |
+ model_view_->SetBoundsRect(rect); |
} |
bool AppListView::OnKeyPressed(const views::KeyEvent& event) { |
@@ -67,10 +108,16 @@ bool AppListView::OnMousePressed(const views::MouseEvent& event) { |
return true; |
} |
-void AppListView::AppListItemActivated(AppListItemView* sender, |
- int event_flags) { |
- if (delegate_.get()) |
- delegate_->OnAppListItemActivated(sender->model(), event_flags); |
+void AppListView::ButtonPressed(views::Button* sender, |
+ const views::Event& event) { |
+ if (sender->GetClassName() != AppListItemView::kViewClassName) |
+ return; |
+ |
+ if (delegate_.get()) { |
+ delegate_->OnAppListItemActivated( |
+ static_cast<AppListItemView*>(sender)->model(), |
+ event.flags()); |
+ } |
Close(); |
} |