Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: ui/app_list/views/app_list_view.cc

Issue 12088037: Revert 179302 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/app_list_view.h ('k') | ui/app_list/views/search_box_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/app_list/views/app_list_view.h" 5 #include "ui/app_list/views/app_list_view.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "ui/app_list/app_list_constants.h" 8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/app_list/app_list_model.h" 9 #include "ui/app_list/app_list_model.h"
10 #include "ui/app_list/app_list_view_delegate.h" 10 #include "ui/app_list/app_list_view_delegate.h"
11 #include "ui/app_list/pagination_model.h" 11 #include "ui/app_list/pagination_model.h"
12 #include "ui/app_list/signin_delegate.h"
13 #include "ui/app_list/views/app_list_background.h" 12 #include "ui/app_list/views/app_list_background.h"
14 #include "ui/app_list/views/app_list_main_view.h" 13 #include "ui/app_list/views/app_list_main_view.h"
15 #include "ui/app_list/views/search_box_view.h" 14 #include "ui/app_list/views/search_box_view.h"
16 #include "ui/app_list/views/signin_view.h"
17 #include "ui/gfx/insets.h" 15 #include "ui/gfx/insets.h"
18 #include "ui/gfx/path.h" 16 #include "ui/gfx/path.h"
19 #include "ui/gfx/skia_util.h" 17 #include "ui/gfx/skia_util.h"
20 #include "ui/views/bubble/bubble_frame_view.h" 18 #include "ui/views/bubble/bubble_frame_view.h"
21 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
22 #include "ui/views/layout/fill_layout.h" 20 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
24 22
25 namespace app_list { 23 namespace app_list {
26 24
27 namespace { 25 namespace {
28 26
29 // The distance between the arrow tip and edge of the anchor view. 27 // The distance between the arrow tip and edge of the anchor view.
30 const int kArrowOffset = 10; 28 const int kArrowOffset = 10;
31 29
32 } // namespace 30 } // namespace
33 31
34 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
35 // AppListView: 33 // AppListView:
36 34
37 AppListView::AppListView(AppListViewDelegate* delegate) 35 AppListView::AppListView(AppListViewDelegate* delegate)
38 : model_(new AppListModel), 36 : model_(new AppListModel),
39 delegate_(delegate), 37 delegate_(delegate),
40 app_list_main_view_(NULL), 38 app_list_main_view_(NULL) {
41 signin_view_(NULL) {
42 if (delegate_) 39 if (delegate_)
43 delegate_->SetModel(model_.get()); 40 delegate_->SetModel(model_.get());
44 if (GetSigninDelegate())
45 GetSigninDelegate()->AddObserver(this);
46 } 41 }
47 42
48 AppListView::~AppListView() { 43 AppListView::~AppListView() {
49 if (GetSigninDelegate())
50 GetSigninDelegate()->RemoveObserver(this);
51
52 // Models are going away, ensure their references are cleared. 44 // Models are going away, ensure their references are cleared.
53 RemoveAllChildViews(true); 45 RemoveAllChildViews(true);
54 } 46 }
55 47
56 void AppListView::InitAsBubble( 48 void AppListView::InitAsBubble(
57 gfx::NativeView parent, 49 gfx::NativeView parent,
58 PaginationModel* pagination_model, 50 PaginationModel* pagination_model,
59 views::View* anchor, 51 views::View* anchor,
60 const gfx::Point& anchor_point, 52 const gfx::Point& anchor_point,
61 views::BubbleBorder::ArrowLocation arrow_location) { 53 views::BubbleBorder::ArrowLocation arrow_location) {
62
63 app_list_main_view_ = new AppListMainView(delegate_.get(), 54 app_list_main_view_ = new AppListMainView(delegate_.get(),
64 model_.get(), 55 model_.get(),
65 pagination_model, 56 pagination_model,
66 anchor); 57 anchor);
67 AddChildView(app_list_main_view_); 58 SetLayoutManager(new views::FillLayout());
59
68 #if defined(USE_AURA) 60 #if defined(USE_AURA)
69 app_list_main_view_->SetPaintToLayer(true); 61 app_list_main_view_->SetPaintToLayer(true);
70 app_list_main_view_->SetFillsBoundsOpaquely(false); 62 app_list_main_view_->SetFillsBoundsOpaquely(false);
71 app_list_main_view_->layer()->SetMasksToBounds(true); 63 app_list_main_view_->layer()->SetMasksToBounds(true);
72 #endif 64 #endif
73 65
74 signin_view_ = new SigninView(GetSigninDelegate()); 66 AddChildView(app_list_main_view_);
75 AddChildView(signin_view_);
76 67
77 set_anchor_view(anchor); 68 set_anchor_view(anchor);
78 set_anchor_point(anchor_point); 69 set_anchor_point(anchor_point);
79 set_color(kContentsBackgroundColor); 70 set_color(kContentsBackgroundColor);
80 set_margins(gfx::Insets()); 71 set_margins(gfx::Insets());
81 set_move_with_anchor(true); 72 set_move_with_anchor(true);
82 set_parent_window(parent); 73 set_parent_window(parent);
83 set_close_on_deactivate(false); 74 set_close_on_deactivate(false);
84 set_close_on_esc(false); 75 set_close_on_esc(false);
85 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset, 76 set_anchor_insets(gfx::Insets(kArrowOffset, kArrowOffset,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (delegate_.get()) 114 if (delegate_.get())
124 delegate_->Dismiss(); 115 delegate_->Dismiss();
125 else 116 else
126 GetWidget()->Close(); 117 GetWidget()->Close();
127 } 118 }
128 119
129 void AppListView::UpdateBounds() { 120 void AppListView::UpdateBounds() {
130 SizeToContents(); 121 SizeToContents();
131 } 122 }
132 123
133 gfx::Size AppListView::GetPreferredSize() {
134 return app_list_main_view_->GetPreferredSize();
135 }
136
137 views::View* AppListView::GetInitiallyFocusedView() { 124 views::View* AppListView::GetInitiallyFocusedView() {
138 return app_list_main_view_->search_box_view()->search_box(); 125 return app_list_main_view_->search_box_view()->search_box();
139 } 126 }
140 127
141 bool AppListView::WidgetHasHitTestMask() const { 128 bool AppListView::WidgetHasHitTestMask() const {
142 return true; 129 return true;
143 } 130 }
144 131
145 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const { 132 void AppListView::GetWidgetHitTestMask(gfx::Path* mask) const {
146 DCHECK(mask); 133 DCHECK(mask);
147 mask->addRect(gfx::RectToSkRect( 134 mask->addRect(gfx::RectToSkRect(
148 GetBubbleFrameView()->GetContentsBounds())); 135 GetBubbleFrameView()->GetContentsBounds()));
149 } 136 }
150 137
151 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) { 138 bool AppListView::AcceleratorPressed(const ui::Accelerator& accelerator) {
152 // The accelerator is added by BubbleDelegateView. 139 // The accelerator is added by BubbleDelegateView.
153 if (accelerator.key_code() == ui::VKEY_ESCAPE) { 140 if (accelerator.key_code() == ui::VKEY_ESCAPE) {
154 Close(); 141 Close();
155 return true; 142 return true;
156 } 143 }
157 144
158 return false; 145 return false;
159 } 146 }
160 147
161 void AppListView::Layout() {
162 if (!signin_view_) {
163 app_list_main_view_->SetBounds(0, 0, width(), height());
164 return;
165 }
166
167 if (GetSigninDelegate() && GetSigninDelegate()->NeedSignin()) {
168 signin_view_->SetBounds(0, 0, width(), height());
169 app_list_main_view_->SetBounds(width(), 0, width(), height());
170 return;
171 }
172
173 signin_view_->SetBounds(-width(), 0, width(), height());
174 app_list_main_view_->SetBounds(0, 0, width(), height());
175 }
176
177 void AppListView::OnWidgetClosing(views::Widget* widget) { 148 void AppListView::OnWidgetClosing(views::Widget* widget) {
178 BubbleDelegateView::OnWidgetClosing(widget); 149 BubbleDelegateView::OnWidgetClosing(widget);
179 if (delegate_.get() && widget == GetWidget()) 150 if (delegate_.get() && widget == GetWidget())
180 delegate_->ViewClosing(); 151 delegate_->ViewClosing();
181 } 152 }
182 153
183 void AppListView::OnWidgetActivationChanged(views::Widget* widget, 154 void AppListView::OnWidgetActivationChanged(views::Widget* widget,
184 bool active) { 155 bool active) {
185 // Do not called inherited function as the bubble delegate auto close 156 // Do not called inherited function as the bubble delegate auto close
186 // functionality is not used. 157 // functionality is not used.
187 if (delegate_.get() && widget == GetWidget()) 158 if (delegate_.get() && widget == GetWidget())
188 delegate_->ViewActivationChanged(active); 159 delegate_->ViewActivationChanged(active);
189 } 160 }
190 161
191 void AppListView::OnWidgetVisibilityChanged(views::Widget* widget,
192 bool visible) {
193 BubbleDelegateView::OnWidgetVisibilityChanged(widget, visible);
194
195 if (widget != GetWidget())
196 return;
197
198 Layout();
199 if (visible && GetSigninDelegate() && GetSigninDelegate()->NeedSignin())
200 signin_view_->BeginSignin();
201 }
202
203 void AppListView::OnSigninSuccess() {
204 Layout();
205 }
206
207 SigninDelegate* AppListView::GetSigninDelegate() {
208 return delegate_ ? delegate_->GetSigninDelegate() : NULL;
209 }
210
211 } // namespace app_list 162 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_view.h ('k') | ui/app_list/views/search_box_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698