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

Side by Side Diff: athena/wm/window_overview_mode.cc

Issue 416243004: Enable touch text selection on Athena (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 4 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 | « athena/wm/window_manager_impl.cc ('k') | 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/wm/window_overview_mode.h" 5 #include "athena/wm/window_overview_mode.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // Prepare the desired transforms for all the windows, and set the initial 104 // Prepare the desired transforms for all the windows, and set the initial
105 // state on the windows. 105 // state on the windows.
106 ComputeTerminalStatesForAllWindows(); 106 ComputeTerminalStatesForAllWindows();
107 SetInitialWindowStates(); 107 SetInitialWindowStates();
108 } 108 }
109 109
110 virtual ~WindowOverviewModeImpl() { 110 virtual ~WindowOverviewModeImpl() {
111 container_->set_target_handler(container_->delegate()); 111 container_->set_target_handler(container_->delegate());
112 112
113 aura::Window::Windows windows = container_->children(); 113 const aura::Window::Windows& windows = container_->children();
114 if (windows.empty()) 114 for (aura::Window::Windows::const_iterator iter = windows.begin();
115 return; 115 iter != windows.end();
116 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); 116 ++iter) {
117 if ((*iter)->GetProperty(kWindowOverviewState))
118 RestoreWindowState(*iter);
119 }
117 } 120 }
118 121
119 private: 122 private:
120 // Computes the transforms for all windows in both the topmost and bottom-most 123 // Computes the transforms for all windows in both the topmost and bottom-most
121 // positions. The transforms are set in the |kWindowOverviewState| property of 124 // positions. The transforms are set in the |kWindowOverviewState| property of
122 // the windows. 125 // the windows.
123 void ComputeTerminalStatesForAllWindows() { 126 void ComputeTerminalStatesForAllWindows() {
124 aura::Window::Windows windows = container_->children(); 127 size_t window_count = 0;
125 size_t window_count = windows.size(); 128 const aura::Window::Windows& windows = container_->children();
129 for (aura::Window::Windows::const_iterator iter = windows.begin();
130 iter != windows.end();
131 ++iter) {
132 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL)
133 window_count++;
134 }
oshima 2014/08/01 23:10:09 I see. you could use count_if, but I'll leave it t
mohsen 2014/08/01 23:36:01 Yep, Done.
135
126 size_t index = 0; 136 size_t index = 0;
127 const gfx::Size container_size = container_->bounds().size(); 137 const gfx::Size container_size = container_->bounds().size();
128 138
129 const int kGapBetweenWindowsBottom = 10; 139 const int kGapBetweenWindowsBottom = 10;
130 const int kGapBetweenWindowsTop = 5; 140 const int kGapBetweenWindowsTop = 5;
131 const float kMinScale = 0.6f; 141 const float kMinScale = 0.6f;
132 const float kMaxScale = 0.95f; 142 const float kMaxScale = 0.95f;
133 143
134 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 144 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
135 iter != windows.rend(); 145 iter != windows.rend();
136 ++iter, ++index) { 146 ++iter) {
137 aura::Window* window = (*iter); 147 aura::Window* window = (*iter);
148 if (window->type() != ui::wm::WINDOW_TYPE_NORMAL)
149 continue;
138 150
139 gfx::Transform top_transform; 151 gfx::Transform top_transform;
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; 152 int top = (window_count - index - 1) * kGapBetweenWindowsTop;
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; 153 float x_translate = container_size.width() * (1 - kMinScale) / 2.;
142 top_transform.Translate(x_translate, top); 154 top_transform.Translate(x_translate, top);
143 top_transform.Scale(kMinScale, kMinScale); 155 top_transform.Scale(kMinScale, kMinScale);
144 156
145 gfx::Transform bottom_transform; 157 gfx::Transform bottom_transform;
146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); 158 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom);
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; 159 x_translate = container_size.width() * (1 - kMaxScale) / 2.;
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); 160 bottom_transform.Translate(x_translate, bottom - window->bounds().y());
149 bottom_transform.Scale(kMaxScale, kMaxScale); 161 bottom_transform.Scale(kMaxScale, kMaxScale);
150 162
151 WindowOverviewState* state = new WindowOverviewState; 163 WindowOverviewState* state = new WindowOverviewState;
152 state->top = top_transform; 164 state->top = top_transform;
153 state->bottom = bottom_transform; 165 state->bottom = bottom_transform;
154 state->progress = 0.f; 166 state->progress = 0.f;
155 state->shadow = CreateShadowForWindow(window); 167 state->shadow = CreateShadowForWindow(window);
156 window->SetProperty(kWindowOverviewState, state); 168 window->SetProperty(kWindowOverviewState, state);
169
170 index++;
157 } 171 }
158 } 172 }
159 173
160 // Sets the initial position for the windows for the overview mode. 174 // Sets the initial position for the windows for the overview mode.
161 void SetInitialWindowStates() { 175 void SetInitialWindowStates() {
162 aura::Window::Windows windows = container_->children();
163 size_t window_count = windows.size();
164 // The initial overview state of the topmost three windows. 176 // The initial overview state of the topmost three windows.
165 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; 177 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f };
166 for (size_t i = 0; i < window_count; ++i) { 178 size_t index = 0;
179 const aura::Window::Windows& windows = container_->children();
180 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
181 iter != windows.rend();
182 ++iter) {
183 aura::Window* window = (*iter);
184 if (!window->GetProperty(kWindowOverviewState))
185 continue;
186
167 float progress = 0.f; 187 float progress = 0.f;
168 aura::Window* window = windows[window_count - 1 - i]; 188 if (index < arraysize(kInitialProgress))
169 if (i < arraysize(kInitialProgress)) 189 progress = kInitialProgress[index];
170 progress = kInitialProgress[i];
171 190
172 scoped_refptr<ui::LayerAnimator> animator = 191 scoped_refptr<ui::LayerAnimator> animator =
173 window->layer()->GetAnimator(); 192 window->layer()->GetAnimator();
174 193
175 // Unset any in-progress animation. 194 // Unset any in-progress animation.
176 { 195 {
177 ui::ScopedLayerAnimationSettings settings(animator); 196 ui::ScopedLayerAnimationSettings settings(animator);
178 settings.SetPreemptionStrategy( 197 settings.SetPreemptionStrategy(
179 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 198 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
180 window->Show(); 199 window->Show();
181 window->SetTransform(gfx::Transform()); 200 window->SetTransform(gfx::Transform());
182 } 201 }
183 // Setup the animation. 202 // Setup the animation.
184 { 203 {
185 ui::ScopedLayerAnimationSettings settings(animator); 204 ui::ScopedLayerAnimationSettings settings(animator);
186 settings.SetPreemptionStrategy( 205 settings.SetPreemptionStrategy(
187 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 206 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
188 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); 207 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250));
189 SetWindowProgress(window, progress); 208 SetWindowProgress(window, progress);
190 } 209 }
210 index++;
191 } 211 }
192 } 212 }
193 213
194 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { 214 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) {
195 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); 215 scoped_ptr<wm::Shadow> shadow(new wm::Shadow());
196 shadow->Init(wm::Shadow::STYLE_ACTIVE); 216 shadow->Init(wm::Shadow::STYLE_ACTIVE);
197 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); 217 shadow->SetContentBounds(gfx::Rect(window->bounds().size()));
198 shadow->layer()->SetVisible(true); 218 shadow->layer()->SetVisible(true);
199 window->layer()->Add(shadow->layer()); 219 window->layer()->Add(shadow->layer());
200 return shadow.Pass(); 220 return shadow.Pass();
(...skipping 14 matching lines...) Expand all
215 targeter->FindTargetForLocatedEvent(container_, event)); 235 targeter->FindTargetForLocatedEvent(container_, event));
216 while (target && target->parent() != container_) 236 while (target && target->parent() != container_)
217 target = target->parent(); 237 target = target->parent();
218 return target; 238 return target;
219 } 239 }
220 240
221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when 241 // Scroll the window list by |delta_y| amount. |delta_y| is negative when
222 // scrolling up; and positive when scrolling down. 242 // scrolling up; and positive when scrolling down.
223 void DoScroll(float delta_y) { 243 void DoScroll(float delta_y) {
224 const float kEpsilon = 1e-3f; 244 const float kEpsilon = 1e-3f;
225 aura::Window::Windows windows = container_->children();
226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); 245 float delta_y_p = std::abs(delta_y) / GetScrollableHeight();
246 const aura::Window::Windows& windows = container_->children();
227 if (delta_y < 0) { 247 if (delta_y < 0) {
228 // Scroll up. Start with the top-most (i.e. behind-most in terms of 248 // Scroll up. Start with the top-most (i.e. behind-most in terms of
229 // z-index) window, and try to scroll them up. 249 // z-index) window, and try to scroll them up.
230 for (aura::Window::Windows::iterator iter = windows.begin(); 250 for (aura::Window::Windows::const_iterator iter = windows.begin();
231 delta_y_p > kEpsilon && iter != windows.end(); 251 delta_y_p > kEpsilon && iter != windows.end();
232 ++iter) { 252 ++iter) {
233 aura::Window* window = (*iter); 253 aura::Window* window = (*iter);
234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 254 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
255 if (!state)
256 continue;
235 if (state->progress > kEpsilon) { 257 if (state->progress > kEpsilon) {
236 // It is possible to scroll |window| up. Scroll it up, and update 258 // It is possible to scroll |window| up. Scroll it up, and update
237 // |delta_y_p| for the next window. 259 // |delta_y_p| for the next window.
238 float apply = delta_y_p * state->progress; 260 float apply = delta_y_p * state->progress;
239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); 261 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3));
240 delta_y_p -= apply; 262 delta_y_p -= apply;
241 } 263 }
242 } 264 }
243 } else { 265 } else {
244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of 266 // Scroll down. Start with the bottom-most (i.e. front-most in terms of
245 // z-index) window, and try to scroll them down. 267 // z-index) window, and try to scroll them down.
246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 268 for (aura::Window::Windows::const_reverse_iterator iter =
269 windows.rbegin();
247 delta_y_p > kEpsilon && iter != windows.rend(); 270 delta_y_p > kEpsilon && iter != windows.rend();
248 ++iter) { 271 ++iter) {
249 aura::Window* window = (*iter); 272 aura::Window* window = (*iter);
250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 273 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
274 if (!state)
275 continue;
251 if (1.f - state->progress > kEpsilon) { 276 if (1.f - state->progress > kEpsilon) {
252 // It is possible to scroll |window| down. Scroll it down, and update 277 // It is possible to scroll |window| down. Scroll it down, and update
253 // |delta_y_p| for the next window. 278 // |delta_y_p| for the next window.
254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); 279 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
255 delta_y_p /= 2.f; 280 delta_y_p /= 2.f;
256 } 281 }
257 } 282 }
258 } 283 }
259 } 284 }
260 285
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 329
305 // static 330 // static
306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 331 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
307 aura::Window* container, 332 aura::Window* container,
308 WindowOverviewModeDelegate* delegate) { 333 WindowOverviewModeDelegate* delegate) {
309 return scoped_ptr<WindowOverviewMode>( 334 return scoped_ptr<WindowOverviewMode>(
310 new WindowOverviewModeImpl(container, delegate)); 335 new WindowOverviewModeImpl(container, delegate));
311 } 336 }
312 337
313 } // namespace athena 338 } // namespace athena
OLDNEW
« no previous file with comments | « athena/wm/window_manager_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698