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

Side by Side Diff: athena/home/home_card_impl.cc

Issue 693103002: Fixes the mouse click of the search box in the home card. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "athena/home/app_list_view_delegate.h" 11 #include "athena/home/app_list_view_delegate.h"
12 #include "athena/home/athena_start_page_view.h" 12 #include "athena/home/athena_start_page_view.h"
13 #include "athena/home/home_card_constants.h" 13 #include "athena/home/home_card_constants.h"
14 #include "athena/home/public/app_model_builder.h" 14 #include "athena/home/public/app_model_builder.h"
15 #include "athena/screen/public/screen_manager.h" 15 #include "athena/screen/public/screen_manager.h"
16 #include "athena/util/container_priorities.h" 16 #include "athena/util/container_priorities.h"
17 #include "athena/wm/public/window_manager.h" 17 #include "athena/wm/public/window_manager.h"
18 #include "ui/app_list/views/app_list_main_view.h" 18 #include "ui/app_list/views/app_list_main_view.h"
19 #include "ui/app_list/views/contents_view.h" 19 #include "ui/app_list/views/contents_view.h"
20 #include "ui/aura/layout_manager.h" 20 #include "ui/aura/layout_manager.h"
21 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
22 #include "ui/compositor/closure_animation_observer.h"
22 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
23 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
24 #include "ui/gfx/animation/tween.h" 25 #include "ui/gfx/animation/tween.h"
25 #include "ui/views/background.h" 26 #include "ui/views/background.h"
26 #include "ui/views/layout/fill_layout.h" 27 #include "ui/views/layout/fill_layout.h"
27 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
28 #include "ui/views/widget/widget_delegate.h" 29 #include "ui/views/widget/widget_delegate.h"
29 #include "ui/wm/core/shadow_types.h" 30 #include "ui/wm/core/shadow_types.h"
30 #include "ui/wm/core/visibility_controller.h" 31 #include "ui/wm/core/visibility_controller.h"
31 32
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 class HomeCardView : public views::WidgetDelegateView, 125 class HomeCardView : public views::WidgetDelegateView,
125 public AthenaStartPageView::Observer { 126 public AthenaStartPageView::Observer {
126 public: 127 public:
127 HomeCardView(app_list::AppListViewDelegate* view_delegate, 128 HomeCardView(app_list::AppListViewDelegate* view_delegate,
128 aura::Window* container, 129 aura::Window* container,
129 HomeCardGestureManager::Delegate* gesture_delegate) 130 HomeCardGestureManager::Delegate* gesture_delegate)
130 : background_(new views::View), 131 : background_(new views::View),
131 main_view_(new AthenaStartPageView(view_delegate)), 132 main_view_(new AthenaStartPageView(view_delegate)),
132 minimized_background_(new views::View()), 133 minimized_background_(new views::View()),
133 drag_indicator_(new views::View()), 134 drag_indicator_(new views::View()),
134 gesture_delegate_(gesture_delegate) { 135 gesture_delegate_(gesture_delegate),
136 weak_factory_(this) {
135 background_->set_background( 137 background_->set_background(
136 views::Background::CreateVerticalGradientBackground(SK_ColorLTGRAY, 138 views::Background::CreateVerticalGradientBackground(SK_ColorLTGRAY,
137 SK_ColorWHITE)); 139 SK_ColorWHITE));
138 background_->SetPaintToLayer(true); 140 background_->SetPaintToLayer(true);
139 background_->SetFillsBoundsOpaquely(false); 141 background_->SetFillsBoundsOpaquely(false);
140 AddChildView(background_); 142 AddChildView(background_);
141 143
142 // Ideally AppListMainView should be used here and have AthenaStartPageView 144 // Ideally AppListMainView should be used here and have AthenaStartPageView
143 // as its child view, so that custom pages and apps grid are available in 145 // as its child view, so that custom pages and apps grid are available in
144 // the home card. 146 // the home card.
145 // TODO(mukai): make it so after the detailed UI has been fixed. 147 // TODO(mukai): make it so after the detailed UI has been fixed.
146 main_view_->AddObserver(this); 148 main_view_->AddObserver(this);
147 AddChildView(main_view_); 149 AddChildView(main_view_);
148 150
149 minimized_background_->set_background( 151 minimized_background_->set_background(
150 views::Background::CreateSolidBackground( 152 views::Background::CreateSolidBackground(
151 SkColorSetA(SK_ColorBLACK, 256 * kMinimizedHomeOpacity))); 153 SkColorSetA(SK_ColorBLACK, 256 * kMinimizedHomeOpacity)));
152 minimized_background_->SetPaintToLayer(true); 154 minimized_background_->SetPaintToLayer(true);
153 minimized_background_->SetFillsBoundsOpaquely(false); 155 minimized_background_->SetFillsBoundsOpaquely(false);
154 minimized_background_->layer()->set_name("MinimizedBackground"); 156 minimized_background_->layer()->set_name("MinimizedBackground");
155 AddChildView(minimized_background_); 157 AddChildView(minimized_background_);
yoshiki 2014/11/04 06:49:29 Just out of curiosity, why do you add the minimize
156 158
157 drag_indicator_->set_background( 159 drag_indicator_->set_background(
158 views::Background::CreateSolidBackground(SK_ColorWHITE)); 160 views::Background::CreateSolidBackground(SK_ColorWHITE));
159 drag_indicator_->SetPaintToLayer(true); 161 drag_indicator_->SetPaintToLayer(true);
160 AddChildView(drag_indicator_); 162 AddChildView(drag_indicator_);
161 } 163 }
162 164
163 ~HomeCardView() override { main_view_->RemoveObserver(this); } 165 ~HomeCardView() override { main_view_->RemoveObserver(this); }
164 166
165 void SetStateProgress(HomeCard::State from_state, 167 void SetStateProgress(HomeCard::State from_state,
166 HomeCard::State to_state, 168 HomeCard::State to_state,
167 float progress) { 169 float progress) {
168 // TODO(mukai): not clear the focus, but simply close the virtual keyboard. 170 // TODO(mukai): not clear the focus, but simply close the virtual keyboard.
169 GetFocusManager()->ClearFocus(); 171 GetFocusManager()->ClearFocus();
170 if (from_state == HomeCard::VISIBLE_CENTERED) 172 if (from_state == HomeCard::VISIBLE_CENTERED)
171 main_view_->SetLayoutState(1.0f - progress); 173 main_view_->SetLayoutState(1.0f - progress);
172 else if (to_state == HomeCard::VISIBLE_CENTERED) 174 else if (to_state == HomeCard::VISIBLE_CENTERED)
173 main_view_->SetLayoutState(progress); 175 main_view_->SetLayoutState(progress);
174 176
175 float background_opacity = 1.0f; 177 float background_opacity = 1.0f;
176 if (from_state == HomeCard::VISIBLE_MINIMIZED || 178 if (from_state == HomeCard::VISIBLE_MINIMIZED ||
177 to_state == HomeCard::VISIBLE_MINIMIZED) { 179 to_state == HomeCard::VISIBLE_MINIMIZED) {
178 background_opacity = (from_state == HomeCard::VISIBLE_MINIMIZED) 180 background_opacity = (from_state == HomeCard::VISIBLE_MINIMIZED)
179 ? progress 181 ? progress
180 : (1.0f - progress); 182 : (1.0f - progress);
181 } 183 }
182 background_->layer()->SetOpacity(background_opacity); 184 background_->layer()->SetOpacity(background_opacity);
183 minimized_background_->layer()->SetOpacity(1.0f - background_opacity); 185 minimized_background_->layer()->SetOpacity(1.0f - background_opacity);
186 UpdateMinimizedBackgroundVisibility();
184 187
185 int background_height = kHomeCardHeight; 188 int background_height = kHomeCardHeight;
186 if (from_state == HomeCard::VISIBLE_CENTERED || 189 if (from_state == HomeCard::VISIBLE_CENTERED ||
187 to_state == HomeCard::VISIBLE_CENTERED) { 190 to_state == HomeCard::VISIBLE_CENTERED) {
188 gfx::Rect window_bounds = GetWidget()->GetWindowBoundsInScreen(); 191 gfx::Rect window_bounds = GetWidget()->GetWindowBoundsInScreen();
189 background_height = window_bounds.height() - window_bounds.y(); 192 background_height = window_bounds.height() - window_bounds.y();
190 } 193 }
191 gfx::Transform background_transform; 194 gfx::Transform background_transform;
192 background_transform.Scale( 195 background_transform.Scale(
193 SK_MScalar1, 196 SK_MScalar1,
194 SkIntToMScalar(background_height) / SkIntToMScalar(height())); 197 SkIntToMScalar(background_height) / SkIntToMScalar(height()));
195 background_->layer()->SetTransform(background_transform); 198 background_->layer()->SetTransform(background_transform);
196 199
197 gfx::Rect from_bounds = GetDragIndicatorBounds(from_state); 200 gfx::Rect from_bounds = GetDragIndicatorBounds(from_state);
198 gfx::Rect to_bounds = GetDragIndicatorBounds(to_state); 201 gfx::Rect to_bounds = GetDragIndicatorBounds(to_state);
199 if (from_bounds != to_bounds) { 202 if (from_bounds != to_bounds) {
200 DCHECK_EQ(from_bounds.size().ToString(), to_bounds.size().ToString()); 203 DCHECK_EQ(from_bounds.size().ToString(), to_bounds.size().ToString());
201 drag_indicator_->SetBoundsRect( 204 drag_indicator_->SetBoundsRect(
202 gfx::Tween::RectValueBetween(progress, from_bounds, to_bounds)); 205 gfx::Tween::RectValueBetween(progress, from_bounds, to_bounds));
203 } 206 }
204 } 207 }
205 208
206 void SetStateWithAnimation(HomeCard::State state, 209 void SetStateWithAnimation(HomeCard::State state,
207 gfx::Tween::Type tween_type) { 210 gfx::Tween::Type tween_type) {
208 float minimized_opacity = 211 float minimized_opacity =
209 (state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f; 212 (state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f;
213 // |minimized_background_| needs to be visible before scheduling animation.
214 if (state == HomeCard::VISIBLE_MINIMIZED)
215 minimized_background_->SetVisible(true);
216
210 if (minimized_opacity != 217 if (minimized_opacity !=
211 minimized_background_->layer()->GetTargetOpacity()) { 218 minimized_background_->layer()->GetTargetOpacity()) {
212 ui::ScopedLayerAnimationSettings settings( 219 ui::ScopedLayerAnimationSettings settings(
213 minimized_background_->layer()->GetAnimator()); 220 minimized_background_->layer()->GetAnimator());
214 settings.SetTweenType(gfx::Tween::EASE_IN); 221 settings.SetTweenType(gfx::Tween::EASE_IN);
222 settings.AddObserver(new ui::ClosureAnimationObserver(
223 base::Bind(&HomeCardView::UpdateMinimizedBackgroundVisibility,
224 weak_factory_.GetWeakPtr())));
215 minimized_background_->layer()->SetOpacity(minimized_opacity); 225 minimized_background_->layer()->SetOpacity(minimized_opacity);
216 } 226 }
217 227
218 gfx::Transform background_transform; 228 gfx::Transform background_transform;
219 if (state != HomeCard::VISIBLE_CENTERED) { 229 if (state != HomeCard::VISIBLE_CENTERED) {
220 background_transform.Scale( 230 background_transform.Scale(
221 SK_MScalar1, 231 SK_MScalar1,
222 SkIntToMScalar(kHomeCardHeight) / SkIntToMScalar(height())); 232 SkIntToMScalar(kHomeCardHeight) / SkIntToMScalar(height()));
223 } 233 }
224 float background_opacity = 1.0f - minimized_opacity; 234 float background_opacity = 1.0f - minimized_opacity;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 void Layout() override { 296 void Layout() override {
287 gfx::Rect contents_bounds = GetContentsBounds(); 297 gfx::Rect contents_bounds = GetContentsBounds();
288 background_->SetBoundsRect(contents_bounds); 298 background_->SetBoundsRect(contents_bounds);
289 main_view_->SetBoundsRect(contents_bounds); 299 main_view_->SetBoundsRect(contents_bounds);
290 minimized_background_->SetBoundsRect(contents_bounds); 300 minimized_background_->SetBoundsRect(contents_bounds);
291 drag_indicator_->SetBoundsRect( 301 drag_indicator_->SetBoundsRect(
292 GetDragIndicatorBounds(HomeCard::Get()->GetState())); 302 GetDragIndicatorBounds(HomeCard::Get()->GetState()));
293 } 303 }
294 304
295 private: 305 private:
306 void UpdateMinimizedBackgroundVisibility() {
307 minimized_background_->SetVisible(
308 minimized_background_->layer()->GetTargetOpacity() != 0.0f);
309 }
310
296 // views::WidgetDelegate: 311 // views::WidgetDelegate:
297 views::View* GetContentsView() override { return this; } 312 views::View* GetContentsView() override { return this; }
298 313
299 // AthenaStartPageView::Observer: 314 // AthenaStartPageView::Observer:
300 void OnLayoutStateChanged(float new_state) override { 315 void OnLayoutStateChanged(float new_state) override {
301 if (new_state == 1.0f) 316 if (new_state == 1.0f)
302 HomeCard::Get()->SetState(HomeCard::VISIBLE_CENTERED); 317 HomeCard::Get()->SetState(HomeCard::VISIBLE_CENTERED);
303 } 318 }
304 319
305 views::View* background_; 320 views::View* background_;
306 AthenaStartPageView* main_view_; 321 AthenaStartPageView* main_view_;
307 views::View* minimized_background_; 322 views::View* minimized_background_;
308 views::View* drag_indicator_; 323 views::View* drag_indicator_;
309 HomeCard::State state_; 324 HomeCard::State state_;
310 scoped_ptr<HomeCardGestureManager> gesture_manager_; 325 scoped_ptr<HomeCardGestureManager> gesture_manager_;
311 HomeCardGestureManager::Delegate* gesture_delegate_; 326 HomeCardGestureManager::Delegate* gesture_delegate_;
312 327
328 base::WeakPtrFactory<HomeCardView> weak_factory_;
329
313 DISALLOW_COPY_AND_ASSIGN(HomeCardView); 330 DISALLOW_COPY_AND_ASSIGN(HomeCardView);
314 }; 331 };
315 332
316 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder, 333 HomeCardImpl::HomeCardImpl(scoped_ptr<AppModelBuilder> model_builder,
317 scoped_ptr<SearchControllerFactory> search_factory) 334 scoped_ptr<SearchControllerFactory> search_factory)
318 : model_builder_(model_builder.Pass()), 335 : model_builder_(model_builder.Pass()),
319 search_factory_(search_factory.Pass()), 336 search_factory_(search_factory.Pass()),
320 state_(HIDDEN), 337 state_(HIDDEN),
321 original_state_(VISIBLE_MINIMIZED), 338 original_state_(VISIBLE_MINIMIZED),
322 home_card_widget_(nullptr), 339 home_card_widget_(nullptr),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 instance = nullptr; 519 instance = nullptr;
503 } 520 }
504 521
505 // static 522 // static
506 HomeCard* HomeCard::Get() { 523 HomeCard* HomeCard::Get() {
507 DCHECK(instance); 524 DCHECK(instance);
508 return instance; 525 return instance;
509 } 526 }
510 527
511 } // namespace athena 528 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698