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

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: Get windows list from container in overview mode 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 public ui::EventHandler { 92 public ui::EventHandler {
93 public: 93 public:
94 WindowOverviewModeImpl(aura::Window* container, 94 WindowOverviewModeImpl(aura::Window* container,
95 WindowOverviewModeDelegate* delegate) 95 WindowOverviewModeDelegate* delegate)
96 : container_(container), 96 : container_(container),
97 delegate_(delegate), 97 delegate_(delegate),
98 scoped_targeter_(new aura::ScopedWindowTargeter( 98 scoped_targeter_(new aura::ScopedWindowTargeter(
99 container, 99 container,
100 scoped_ptr<ui::EventTargeter>( 100 scoped_ptr<ui::EventTargeter>(
101 new StaticWindowTargeter(container)))) { 101 new StaticWindowTargeter(container)))) {
102 const aura::Window::Windows& children = container->children();
103 for (aura::Window::Windows::const_iterator iter = children.begin();
104 iter != children.end(); iter++) {
105 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL)
106 windows_.push_back(*iter);
107 }
108
102 container_->set_target_handler(this); 109 container_->set_target_handler(this);
103 110
104 // Prepare the desired transforms for all the windows, and set the initial 111 // Prepare the desired transforms for all the windows, and set the initial
105 // state on the windows. 112 // state on the windows.
106 ComputeTerminalStatesForAllWindows(); 113 ComputeTerminalStatesForAllWindows();
107 SetInitialWindowStates(); 114 SetInitialWindowStates();
108 } 115 }
109 116
110 virtual ~WindowOverviewModeImpl() { 117 virtual ~WindowOverviewModeImpl() {
111 container_->set_target_handler(container_->delegate()); 118 container_->set_target_handler(container_->delegate());
112 119
113 aura::Window::Windows windows = container_->children(); 120 if (windows_.empty())
114 if (windows.empty())
115 return; 121 return;
116 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); 122 std::for_each(windows_.begin(), windows_.end(), &RestoreWindowState);
117 } 123 }
118 124
119 private: 125 private:
120 // Computes the transforms for all windows in both the topmost and bottom-most 126 // Computes the transforms for all windows in both the topmost and bottom-most
121 // positions. The transforms are set in the |kWindowOverviewState| property of 127 // positions. The transforms are set in the |kWindowOverviewState| property of
122 // the windows. 128 // the windows.
123 void ComputeTerminalStatesForAllWindows() { 129 void ComputeTerminalStatesForAllWindows() {
124 aura::Window::Windows windows = container_->children(); 130 size_t window_count = windows_.size();
125 size_t window_count = windows.size();
126 size_t index = 0; 131 size_t index = 0;
127 const gfx::Size container_size = container_->bounds().size(); 132 const gfx::Size container_size = container_->bounds().size();
128 133
129 const int kGapBetweenWindowsBottom = 10; 134 const int kGapBetweenWindowsBottom = 10;
130 const int kGapBetweenWindowsTop = 5; 135 const int kGapBetweenWindowsTop = 5;
131 const float kMinScale = 0.6f; 136 const float kMinScale = 0.6f;
132 const float kMaxScale = 0.95f; 137 const float kMaxScale = 0.95f;
133 138
134 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 139 for (aura::Window::Windows::reverse_iterator iter = windows_.rbegin();
135 iter != windows.rend(); 140 iter != windows_.rend();
136 ++iter, ++index) { 141 ++iter, ++index) {
137 aura::Window* window = (*iter); 142 aura::Window* window = (*iter);
138 143
139 gfx::Transform top_transform; 144 gfx::Transform top_transform;
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; 145 int top = (window_count - index - 1) * kGapBetweenWindowsTop;
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; 146 float x_translate = container_size.width() * (1 - kMinScale) / 2.;
142 top_transform.Translate(x_translate, top); 147 top_transform.Translate(x_translate, top);
143 top_transform.Scale(kMinScale, kMinScale); 148 top_transform.Scale(kMinScale, kMinScale);
144 149
145 gfx::Transform bottom_transform; 150 gfx::Transform bottom_transform;
146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); 151 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom);
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; 152 x_translate = container_size.width() * (1 - kMaxScale) / 2.;
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); 153 bottom_transform.Translate(x_translate, bottom - window->bounds().y());
149 bottom_transform.Scale(kMaxScale, kMaxScale); 154 bottom_transform.Scale(kMaxScale, kMaxScale);
150 155
151 WindowOverviewState* state = new WindowOverviewState; 156 WindowOverviewState* state = new WindowOverviewState;
152 state->top = top_transform; 157 state->top = top_transform;
153 state->bottom = bottom_transform; 158 state->bottom = bottom_transform;
154 state->progress = 0.f; 159 state->progress = 0.f;
155 state->shadow = CreateShadowForWindow(window); 160 state->shadow = CreateShadowForWindow(window);
156 window->SetProperty(kWindowOverviewState, state); 161 window->SetProperty(kWindowOverviewState, state);
157 } 162 }
158 } 163 }
159 164
160 // Sets the initial position for the windows for the overview mode. 165 // Sets the initial position for the windows for the overview mode.
161 void SetInitialWindowStates() { 166 void SetInitialWindowStates() {
162 aura::Window::Windows windows = container_->children(); 167 size_t window_count = windows_.size();
163 size_t window_count = windows.size();
164 // The initial overview state of the topmost three windows. 168 // The initial overview state of the topmost three windows.
165 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; 169 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f };
166 for (size_t i = 0; i < window_count; ++i) { 170 for (size_t i = 0; i < window_count; ++i) {
167 float progress = 0.f; 171 float progress = 0.f;
168 aura::Window* window = windows[window_count - 1 - i]; 172 aura::Window* window = windows_[window_count - 1 - i];
169 if (i < arraysize(kInitialProgress)) 173 if (i < arraysize(kInitialProgress))
170 progress = kInitialProgress[i]; 174 progress = kInitialProgress[i];
171 175
172 scoped_refptr<ui::LayerAnimator> animator = 176 scoped_refptr<ui::LayerAnimator> animator =
173 window->layer()->GetAnimator(); 177 window->layer()->GetAnimator();
174 178
175 // Unset any in-progress animation. 179 // Unset any in-progress animation.
176 { 180 {
177 ui::ScopedLayerAnimationSettings settings(animator); 181 ui::ScopedLayerAnimationSettings settings(animator);
178 settings.SetPreemptionStrategy( 182 settings.SetPreemptionStrategy(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 targeter->FindTargetForLocatedEvent(container_, event)); 219 targeter->FindTargetForLocatedEvent(container_, event));
216 while (target && target->parent() != container_) 220 while (target && target->parent() != container_)
217 target = target->parent(); 221 target = target->parent();
218 return target; 222 return target;
219 } 223 }
220 224
221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when 225 // Scroll the window list by |delta_y| amount. |delta_y| is negative when
222 // scrolling up; and positive when scrolling down. 226 // scrolling up; and positive when scrolling down.
223 void DoScroll(float delta_y) { 227 void DoScroll(float delta_y) {
224 const float kEpsilon = 1e-3f; 228 const float kEpsilon = 1e-3f;
225 aura::Window::Windows windows = container_->children();
226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); 229 float delta_y_p = std::abs(delta_y) / GetScrollableHeight();
227 if (delta_y < 0) { 230 if (delta_y < 0) {
228 // Scroll up. Start with the top-most (i.e. behind-most in terms of 231 // Scroll up. Start with the top-most (i.e. behind-most in terms of
229 // z-index) window, and try to scroll them up. 232 // z-index) window, and try to scroll them up.
230 for (aura::Window::Windows::iterator iter = windows.begin(); 233 for (aura::Window::Windows::iterator iter = windows_.begin();
231 delta_y_p > kEpsilon && iter != windows.end(); 234 delta_y_p > kEpsilon && iter != windows_.end();
232 ++iter) { 235 ++iter) {
233 aura::Window* window = (*iter); 236 aura::Window* window = (*iter);
234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 237 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
235 if (state->progress > kEpsilon) { 238 if (state->progress > kEpsilon) {
236 // It is possible to scroll |window| up. Scroll it up, and update 239 // It is possible to scroll |window| up. Scroll it up, and update
237 // |delta_y_p| for the next window. 240 // |delta_y_p| for the next window.
238 float apply = delta_y_p * state->progress; 241 float apply = delta_y_p * state->progress;
239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); 242 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3));
240 delta_y_p -= apply; 243 delta_y_p -= apply;
241 } 244 }
242 } 245 }
243 } else { 246 } else {
244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of 247 // Scroll down. Start with the bottom-most (i.e. front-most in terms of
245 // z-index) window, and try to scroll them down. 248 // z-index) window, and try to scroll them down.
246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 249 for (aura::Window::Windows::reverse_iterator iter = windows_.rbegin();
247 delta_y_p > kEpsilon && iter != windows.rend(); 250 delta_y_p > kEpsilon && iter != windows_.rend();
248 ++iter) { 251 ++iter) {
249 aura::Window* window = (*iter); 252 aura::Window* window = (*iter);
250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 253 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
251 if (1.f - state->progress > kEpsilon) { 254 if (1.f - state->progress > kEpsilon) {
252 // It is possible to scroll |window| down. Scroll it down, and update 255 // It is possible to scroll |window| down. Scroll it down, and update
253 // |delta_y_p| for the next window. 256 // |delta_y_p| for the next window.
254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); 257 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
255 delta_y_p /= 2.f; 258 delta_y_p /= 2.f;
256 } 259 }
257 } 260 }
(...skipping 29 matching lines...) Expand all
287 if (select) { 290 if (select) {
288 gesture->SetHandled(); 291 gesture->SetHandled();
289 delegate_->OnSelectWindow(select); 292 delegate_->OnSelectWindow(select);
290 } 293 }
291 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 294 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
292 DoScroll(gesture->details().scroll_y()); 295 DoScroll(gesture->details().scroll_y());
293 } 296 }
294 } 297 }
295 298
296 aura::Window* container_; 299 aura::Window* container_;
300 aura::Window::Windows windows_;
oshima 2014/08/01 20:27:14 you can just use container's children and property
mohsen 2014/08/01 20:44:35 OK. I think I see what you say. My only concern wo
297 WindowOverviewModeDelegate* delegate_; 301 WindowOverviewModeDelegate* delegate_;
298 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 302 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
299 303
300 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 304 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
301 }; 305 };
302 306
303 } // namespace 307 } // namespace
304 308
305 // static 309 // static
306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 310 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
307 aura::Window* container, 311 aura::Window* container,
308 WindowOverviewModeDelegate* delegate) { 312 WindowOverviewModeDelegate* delegate) {
309 return scoped_ptr<WindowOverviewMode>( 313 return scoped_ptr<WindowOverviewMode>(
310 new WindowOverviewModeImpl(container, delegate)); 314 new WindowOverviewModeImpl(container, delegate));
311 } 315 }
312 316
313 } // namespace athena 317 } // 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