OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/home/home_card_impl.h" | 5 #include "athena/home/home_card_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "athena/env/public/athena_env.h" | 10 #include "athena/env/public/athena_env.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 120 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
121 }; | 121 }; |
122 | 122 |
123 // The container view of home card contents of each state. | 123 // The container view of home card contents of each state. |
124 class HomeCardView : public views::WidgetDelegateView, | 124 class HomeCardView : public views::WidgetDelegateView, |
125 public AthenaStartPageView::Observer { | 125 public AthenaStartPageView::Observer { |
126 public: | 126 public: |
127 HomeCardView(app_list::AppListViewDelegate* view_delegate, | 127 HomeCardView(app_list::AppListViewDelegate* view_delegate, |
128 aura::Window* container, | 128 aura::Window* container, |
129 HomeCardGestureManager::Delegate* gesture_delegate) | 129 HomeCardGestureManager::Delegate* gesture_delegate) |
130 : minimized_background_(new views::View()), | 130 : background_(new views::View), |
| 131 main_view_(new AthenaStartPageView(view_delegate)), |
| 132 minimized_background_(new views::View()), |
131 drag_indicator_(new views::View()), | 133 drag_indicator_(new views::View()), |
132 main_view_(new AthenaStartPageView(view_delegate)), | |
133 gesture_delegate_(gesture_delegate) { | 134 gesture_delegate_(gesture_delegate) { |
| 135 background_->set_background( |
| 136 views::Background::CreateVerticalGradientBackground(SK_ColorLTGRAY, |
| 137 SK_ColorWHITE)); |
| 138 background_->SetPaintToLayer(true); |
| 139 background_->SetFillsBoundsOpaquely(false); |
| 140 AddChildView(background_); |
| 141 |
134 // Ideally AppListMainView should be used here and have AthenaStartPageView | 142 // Ideally AppListMainView should be used here and have AthenaStartPageView |
135 // as its child view, so that custom pages and apps grid are available in | 143 // as its child view, so that custom pages and apps grid are available in |
136 // the home card. | 144 // the home card. |
137 // TODO(mukai): make it so after the detailed UI has been fixed. | 145 // TODO(mukai): make it so after the detailed UI has been fixed. |
138 main_view_->AddObserver(this); | 146 main_view_->AddObserver(this); |
139 AddChildView(main_view_); | 147 AddChildView(main_view_); |
140 | 148 |
141 minimized_background_->set_background( | 149 minimized_background_->set_background( |
142 views::Background::CreateSolidBackground( | 150 views::Background::CreateSolidBackground( |
143 SkColorSetA(SK_ColorBLACK, 256 * kMinimizedHomeOpacity))); | 151 SkColorSetA(SK_ColorBLACK, 256 * kMinimizedHomeOpacity))); |
(...skipping 12 matching lines...) Expand all Loading... |
156 | 164 |
157 void SetStateProgress(HomeCard::State from_state, | 165 void SetStateProgress(HomeCard::State from_state, |
158 HomeCard::State to_state, | 166 HomeCard::State to_state, |
159 float progress) { | 167 float progress) { |
160 // TODO(mukai): not clear the focus, but simply close the virtual keyboard. | 168 // TODO(mukai): not clear the focus, but simply close the virtual keyboard. |
161 GetFocusManager()->ClearFocus(); | 169 GetFocusManager()->ClearFocus(); |
162 if (from_state == HomeCard::VISIBLE_CENTERED) | 170 if (from_state == HomeCard::VISIBLE_CENTERED) |
163 main_view_->SetLayoutState(1.0f - progress); | 171 main_view_->SetLayoutState(1.0f - progress); |
164 else if (to_state == HomeCard::VISIBLE_CENTERED) | 172 else if (to_state == HomeCard::VISIBLE_CENTERED) |
165 main_view_->SetLayoutState(progress); | 173 main_view_->SetLayoutState(progress); |
| 174 |
| 175 float background_opacity = 1.0f; |
166 if (from_state == HomeCard::VISIBLE_MINIMIZED || | 176 if (from_state == HomeCard::VISIBLE_MINIMIZED || |
167 to_state == HomeCard::VISIBLE_MINIMIZED) { | 177 to_state == HomeCard::VISIBLE_MINIMIZED) { |
168 minimized_background_->layer()->SetOpacity( | 178 background_opacity = (from_state == HomeCard::VISIBLE_MINIMIZED) |
169 (to_state == HomeCard::VISIBLE_MINIMIZED) ? progress | 179 ? progress |
170 : (1.0f - progress)); | 180 : (1.0f - progress); |
171 } | 181 } |
| 182 background_->layer()->SetOpacity(background_opacity); |
| 183 minimized_background_->layer()->SetOpacity(1.0f - background_opacity); |
| 184 |
| 185 int background_height = kHomeCardHeight; |
| 186 if (from_state == HomeCard::VISIBLE_CENTERED || |
| 187 to_state == HomeCard::VISIBLE_CENTERED) { |
| 188 gfx::Rect window_bounds = GetWidget()->GetWindowBoundsInScreen(); |
| 189 background_height = window_bounds.height() - window_bounds.y(); |
| 190 } |
| 191 gfx::Transform background_transform; |
| 192 background_transform.Scale( |
| 193 SK_MScalar1, |
| 194 SkIntToMScalar(background_height) / SkIntToMScalar(height())); |
| 195 background_->layer()->SetTransform(background_transform); |
172 | 196 |
173 gfx::Rect from_bounds = GetDragIndicatorBounds(from_state); | 197 gfx::Rect from_bounds = GetDragIndicatorBounds(from_state); |
174 gfx::Rect to_bounds = GetDragIndicatorBounds(to_state); | 198 gfx::Rect to_bounds = GetDragIndicatorBounds(to_state); |
175 if (from_bounds != to_bounds) { | 199 if (from_bounds != to_bounds) { |
176 DCHECK_EQ(from_bounds.size().ToString(), to_bounds.size().ToString()); | 200 DCHECK_EQ(from_bounds.size().ToString(), to_bounds.size().ToString()); |
177 drag_indicator_->SetBoundsRect( | 201 drag_indicator_->SetBoundsRect( |
178 gfx::Tween::RectValueBetween(progress, from_bounds, to_bounds)); | 202 gfx::Tween::RectValueBetween(progress, from_bounds, to_bounds)); |
179 } | 203 } |
180 } | 204 } |
181 | 205 |
182 void SetStateWithAnimation(HomeCard::State state, | 206 void SetStateWithAnimation(HomeCard::State state, |
183 gfx::Tween::Type tween_type) { | 207 gfx::Tween::Type tween_type) { |
184 float minimized_target_opacity_for_state = | 208 float minimized_opacity = |
185 (state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f; | 209 (state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f; |
186 if (minimized_target_opacity_for_state != | 210 if (minimized_opacity != |
187 minimized_background_->layer()->GetTargetOpacity()) { | 211 minimized_background_->layer()->GetTargetOpacity()) { |
188 ui::ScopedLayerAnimationSettings settings( | 212 ui::ScopedLayerAnimationSettings settings( |
189 minimized_background_->layer()->GetAnimator()); | 213 minimized_background_->layer()->GetAnimator()); |
190 settings.SetTweenType(gfx::Tween::EASE_IN); | 214 settings.SetTweenType(gfx::Tween::EASE_IN); |
191 minimized_background_->layer()->SetOpacity( | 215 minimized_background_->layer()->SetOpacity(minimized_opacity); |
192 minimized_target_opacity_for_state); | |
193 } | 216 } |
| 217 |
| 218 gfx::Transform background_transform; |
| 219 if (state != HomeCard::VISIBLE_CENTERED) { |
| 220 background_transform.Scale( |
| 221 SK_MScalar1, |
| 222 SkIntToMScalar(kHomeCardHeight) / SkIntToMScalar(height())); |
| 223 } |
| 224 float background_opacity = 1.0f - minimized_opacity; |
| 225 if (background_->layer()->GetTargetTransform() != background_transform || |
| 226 background_->layer()->GetTargetOpacity() != background_opacity) { |
| 227 ui::ScopedLayerAnimationSettings settings( |
| 228 background_->layer()->GetAnimator()); |
| 229 settings.SetTweenType(tween_type); |
| 230 background_->layer()->SetTransform(background_transform); |
| 231 background_->layer()->SetOpacity(background_opacity); |
| 232 } |
| 233 |
194 if (state == HomeCard::VISIBLE_CENTERED) | 234 if (state == HomeCard::VISIBLE_CENTERED) |
195 main_view_->RequestFocusOnSearchBox(); | 235 main_view_->RequestFocusOnSearchBox(); |
196 else | 236 else |
197 GetWidget()->GetFocusManager()->ClearFocus(); | 237 GetWidget()->GetFocusManager()->ClearFocus(); |
198 | 238 |
199 { | 239 { |
200 ui::ScopedLayerAnimationSettings settings( | 240 ui::ScopedLayerAnimationSettings settings( |
201 drag_indicator_->layer()->GetAnimator()); | 241 drag_indicator_->layer()->GetAnimator()); |
202 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); | 242 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); |
203 drag_indicator_->SetBoundsRect(GetDragIndicatorBounds(state)); | 243 drag_indicator_->SetBoundsRect(GetDragIndicatorBounds(state)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 kHomeCardDragIndicatorMarginHeight, | 278 kHomeCardDragIndicatorMarginHeight, |
239 kHomeCardDragIndicatorWidth, | 279 kHomeCardDragIndicatorWidth, |
240 kHomeCardDragIndicatorHeight); | 280 kHomeCardDragIndicatorHeight); |
241 if (state == HomeCard::VISIBLE_CENTERED) | 281 if (state == HomeCard::VISIBLE_CENTERED) |
242 drag_indicator_bounds.Offset(0, kSystemUIHeight); | 282 drag_indicator_bounds.Offset(0, kSystemUIHeight); |
243 return drag_indicator_bounds; | 283 return drag_indicator_bounds; |
244 } | 284 } |
245 | 285 |
246 void Layout() override { | 286 void Layout() override { |
247 gfx::Rect contents_bounds = GetContentsBounds(); | 287 gfx::Rect contents_bounds = GetContentsBounds(); |
| 288 background_->SetBoundsRect(contents_bounds); |
248 main_view_->SetBoundsRect(contents_bounds); | 289 main_view_->SetBoundsRect(contents_bounds); |
249 minimized_background_->SetBoundsRect(contents_bounds); | 290 minimized_background_->SetBoundsRect(contents_bounds); |
250 drag_indicator_->SetBoundsRect( | 291 drag_indicator_->SetBoundsRect( |
251 GetDragIndicatorBounds(HomeCard::Get()->GetState())); | 292 GetDragIndicatorBounds(HomeCard::Get()->GetState())); |
252 } | 293 } |
253 | 294 |
254 private: | 295 private: |
255 // views::WidgetDelegate: | 296 // views::WidgetDelegate: |
256 views::View* GetContentsView() override { return this; } | 297 views::View* GetContentsView() override { return this; } |
257 | 298 |
258 // AthenaStartPageView::Observer: | 299 // AthenaStartPageView::Observer: |
259 void OnLayoutStateChanged(float new_state) override { | 300 void OnLayoutStateChanged(float new_state) override { |
260 if (new_state == 1.0f) | 301 if (new_state == 1.0f) |
261 HomeCard::Get()->SetState(HomeCard::VISIBLE_CENTERED); | 302 HomeCard::Get()->SetState(HomeCard::VISIBLE_CENTERED); |
262 } | 303 } |
263 | 304 |
| 305 views::View* background_; |
| 306 AthenaStartPageView* main_view_; |
264 views::View* minimized_background_; | 307 views::View* minimized_background_; |
265 views::View* drag_indicator_; | 308 views::View* drag_indicator_; |
266 AthenaStartPageView* main_view_; | |
267 HomeCard::State state_; | 309 HomeCard::State state_; |
268 scoped_ptr<HomeCardGestureManager> gesture_manager_; | 310 scoped_ptr<HomeCardGestureManager> gesture_manager_; |
269 HomeCardGestureManager::Delegate* gesture_delegate_; | 311 HomeCardGestureManager::Delegate* gesture_delegate_; |
270 | 312 |
271 DISALLOW_COPY_AND_ASSIGN(HomeCardView); | 313 DISALLOW_COPY_AND_ASSIGN(HomeCardView); |
272 }; | 314 }; |
273 | 315 |
274 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, | 316 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, |
275 scoped_ptr<SearchControllerFactory> search_factory) | 317 scoped_ptr<SearchControllerFactory> search_factory) |
276 : model_builder_(model_builder.Pass()), | 318 : model_builder_(model_builder.Pass()), |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 instance = nullptr; | 502 instance = nullptr; |
461 } | 503 } |
462 | 504 |
463 // static | 505 // static |
464 HomeCard* HomeCard::Get() { | 506 HomeCard* HomeCard::Get() { |
465 DCHECK(instance); | 507 DCHECK(instance); |
466 return instance; | 508 return instance; |
467 } | 509 } |
468 | 510 |
469 } // namespace athena | 511 } // namespace athena |
OLD | NEW |