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

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: Passed windows list to 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
« athena/main/athena_main.cc ('K') | « athena/wm/window_overview_mode.h ('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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "ui/aura/scoped_window_targeter.h" 12 #include "ui/aura/scoped_window_targeter.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h" 13 #include "ui/aura/window_delegate.h"
15 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
16 #include "ui/aura/window_targeter.h" 15 #include "ui/aura/window_targeter.h"
17 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
18 #include "ui/events/event_handler.h" 17 #include "ui/events/event_handler.h"
19 #include "ui/gfx/transform.h" 18 #include "ui/gfx/transform.h"
20 #include "ui/wm/core/shadow.h" 19 #include "ui/wm/core/shadow.h"
21 20
22 namespace { 21 namespace {
23 22
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 84 }
86 85
87 aura::Window* target_; 86 aura::Window* target_;
88 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); 87 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter);
89 }; 88 };
90 89
91 class WindowOverviewModeImpl : public WindowOverviewMode, 90 class WindowOverviewModeImpl : public WindowOverviewMode,
92 public ui::EventHandler { 91 public ui::EventHandler {
93 public: 92 public:
94 WindowOverviewModeImpl(aura::Window* container, 93 WindowOverviewModeImpl(aura::Window* container,
94 const aura::Window::Windows& windows,
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 for (aura::Window::Windows::const_iterator iter = windows.begin();
103 iter != windows.end(); iter++) {
104 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL)
105 windows_.push_back(*iter);
106 }
oshima 2014/08/01 16:09:38 you shouldn't need window_. what you're passing is
sadrul 2014/08/01 16:15:46 The filtering here is done to avoid showing popup
oshima 2014/08/01 20:04:10 you can filter the child of container. No need to
sadrul 2014/08/01 20:05:41 This is in preparation for Mikhail's patch, where
mohsen 2014/08/01 20:22:35 I changed it such that the window list is not pass
107
102 container_->set_target_handler(this); 108 container_->set_target_handler(this);
103 109
104 // Prepare the desired transforms for all the windows, and set the initial 110 // Prepare the desired transforms for all the windows, and set the initial
105 // state on the windows. 111 // state on the windows.
106 ComputeTerminalStatesForAllWindows(); 112 ComputeTerminalStatesForAllWindows();
107 SetInitialWindowStates(); 113 SetInitialWindowStates();
108 } 114 }
109 115
110 virtual ~WindowOverviewModeImpl() { 116 virtual ~WindowOverviewModeImpl() {
111 container_->set_target_handler(container_->delegate()); 117 container_->set_target_handler(container_->delegate());
112 118
113 aura::Window::Windows windows = container_->children(); 119 if (windows_.empty())
114 if (windows.empty())
115 return; 120 return;
116 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); 121 std::for_each(windows_.begin(), windows_.end(), &RestoreWindowState);
117 } 122 }
118 123
119 private: 124 private:
120 // Computes the transforms for all windows in both the topmost and bottom-most 125 // Computes the transforms for all windows in both the topmost and bottom-most
121 // positions. The transforms are set in the |kWindowOverviewState| property of 126 // positions. The transforms are set in the |kWindowOverviewState| property of
122 // the windows. 127 // the windows.
123 void ComputeTerminalStatesForAllWindows() { 128 void ComputeTerminalStatesForAllWindows() {
124 aura::Window::Windows windows = container_->children(); 129 size_t window_count = windows_.size();
125 size_t window_count = windows.size();
126 size_t index = 0; 130 size_t index = 0;
127 const gfx::Size container_size = container_->bounds().size(); 131 const gfx::Size container_size = container_->bounds().size();
128 132
129 const int kGapBetweenWindowsBottom = 10; 133 const int kGapBetweenWindowsBottom = 10;
130 const int kGapBetweenWindowsTop = 5; 134 const int kGapBetweenWindowsTop = 5;
131 const float kMinScale = 0.6f; 135 const float kMinScale = 0.6f;
132 const float kMaxScale = 0.95f; 136 const float kMaxScale = 0.95f;
133 137
134 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 138 for (aura::Window::Windows::reverse_iterator iter = windows_.rbegin();
135 iter != windows.rend(); 139 iter != windows_.rend();
136 ++iter, ++index) { 140 ++iter, ++index) {
137 aura::Window* window = (*iter); 141 aura::Window* window = (*iter);
138 142
139 gfx::Transform top_transform; 143 gfx::Transform top_transform;
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; 144 int top = (window_count - index - 1) * kGapBetweenWindowsTop;
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; 145 float x_translate = container_size.width() * (1 - kMinScale) / 2.;
142 top_transform.Translate(x_translate, top); 146 top_transform.Translate(x_translate, top);
143 top_transform.Scale(kMinScale, kMinScale); 147 top_transform.Scale(kMinScale, kMinScale);
144 148
145 gfx::Transform bottom_transform; 149 gfx::Transform bottom_transform;
146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); 150 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom);
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; 151 x_translate = container_size.width() * (1 - kMaxScale) / 2.;
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); 152 bottom_transform.Translate(x_translate, bottom - window->bounds().y());
149 bottom_transform.Scale(kMaxScale, kMaxScale); 153 bottom_transform.Scale(kMaxScale, kMaxScale);
150 154
151 WindowOverviewState* state = new WindowOverviewState; 155 WindowOverviewState* state = new WindowOverviewState;
152 state->top = top_transform; 156 state->top = top_transform;
153 state->bottom = bottom_transform; 157 state->bottom = bottom_transform;
154 state->progress = 0.f; 158 state->progress = 0.f;
155 state->shadow = CreateShadowForWindow(window); 159 state->shadow = CreateShadowForWindow(window);
156 window->SetProperty(kWindowOverviewState, state); 160 window->SetProperty(kWindowOverviewState, state);
157 } 161 }
158 } 162 }
159 163
160 // Sets the initial position for the windows for the overview mode. 164 // Sets the initial position for the windows for the overview mode.
161 void SetInitialWindowStates() { 165 void SetInitialWindowStates() {
162 aura::Window::Windows windows = container_->children(); 166 size_t window_count = windows_.size();
163 size_t window_count = windows.size();
164 // The initial overview state of the topmost three windows. 167 // The initial overview state of the topmost three windows.
165 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; 168 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f };
166 for (size_t i = 0; i < window_count; ++i) { 169 for (size_t i = 0; i < window_count; ++i) {
167 float progress = 0.f; 170 float progress = 0.f;
168 aura::Window* window = windows[window_count - 1 - i]; 171 aura::Window* window = windows_[window_count - 1 - i];
169 if (i < arraysize(kInitialProgress)) 172 if (i < arraysize(kInitialProgress))
170 progress = kInitialProgress[i]; 173 progress = kInitialProgress[i];
171 174
172 scoped_refptr<ui::LayerAnimator> animator = 175 scoped_refptr<ui::LayerAnimator> animator =
173 window->layer()->GetAnimator(); 176 window->layer()->GetAnimator();
174 177
175 // Unset any in-progress animation. 178 // Unset any in-progress animation.
176 { 179 {
177 ui::ScopedLayerAnimationSettings settings(animator); 180 ui::ScopedLayerAnimationSettings settings(animator);
178 settings.SetPreemptionStrategy( 181 settings.SetPreemptionStrategy(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 targeter->FindTargetForLocatedEvent(container_, event)); 218 targeter->FindTargetForLocatedEvent(container_, event));
216 while (target && target->parent() != container_) 219 while (target && target->parent() != container_)
217 target = target->parent(); 220 target = target->parent();
218 return target; 221 return target;
219 } 222 }
220 223
221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when 224 // Scroll the window list by |delta_y| amount. |delta_y| is negative when
222 // scrolling up; and positive when scrolling down. 225 // scrolling up; and positive when scrolling down.
223 void DoScroll(float delta_y) { 226 void DoScroll(float delta_y) {
224 const float kEpsilon = 1e-3f; 227 const float kEpsilon = 1e-3f;
225 aura::Window::Windows windows = container_->children();
226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); 228 float delta_y_p = std::abs(delta_y) / GetScrollableHeight();
227 if (delta_y < 0) { 229 if (delta_y < 0) {
228 // Scroll up. Start with the top-most (i.e. behind-most in terms of 230 // Scroll up. Start with the top-most (i.e. behind-most in terms of
229 // z-index) window, and try to scroll them up. 231 // z-index) window, and try to scroll them up.
230 for (aura::Window::Windows::iterator iter = windows.begin(); 232 for (aura::Window::Windows::iterator iter = windows_.begin();
231 delta_y_p > kEpsilon && iter != windows.end(); 233 delta_y_p > kEpsilon && iter != windows_.end();
232 ++iter) { 234 ++iter) {
233 aura::Window* window = (*iter); 235 aura::Window* window = (*iter);
234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 236 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
235 if (state->progress > kEpsilon) { 237 if (state->progress > kEpsilon) {
236 // It is possible to scroll |window| up. Scroll it up, and update 238 // It is possible to scroll |window| up. Scroll it up, and update
237 // |delta_y_p| for the next window. 239 // |delta_y_p| for the next window.
238 float apply = delta_y_p * state->progress; 240 float apply = delta_y_p * state->progress;
239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); 241 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3));
240 delta_y_p -= apply; 242 delta_y_p -= apply;
241 } 243 }
242 } 244 }
243 } else { 245 } else {
244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of 246 // Scroll down. Start with the bottom-most (i.e. front-most in terms of
245 // z-index) window, and try to scroll them down. 247 // z-index) window, and try to scroll them down.
246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); 248 for (aura::Window::Windows::reverse_iterator iter = windows_.rbegin();
247 delta_y_p > kEpsilon && iter != windows.rend(); 249 delta_y_p > kEpsilon && iter != windows_.rend();
248 ++iter) { 250 ++iter) {
249 aura::Window* window = (*iter); 251 aura::Window* window = (*iter);
250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); 252 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
251 if (1.f - state->progress > kEpsilon) { 253 if (1.f - state->progress > kEpsilon) {
252 // It is possible to scroll |window| down. Scroll it down, and update 254 // It is possible to scroll |window| down. Scroll it down, and update
253 // |delta_y_p| for the next window. 255 // |delta_y_p| for the next window.
254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); 256 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
255 delta_y_p /= 2.f; 257 delta_y_p /= 2.f;
256 } 258 }
257 } 259 }
(...skipping 29 matching lines...) Expand all
287 if (select) { 289 if (select) {
288 gesture->SetHandled(); 290 gesture->SetHandled();
289 delegate_->OnSelectWindow(select); 291 delegate_->OnSelectWindow(select);
290 } 292 }
291 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 293 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
292 DoScroll(gesture->details().scroll_y()); 294 DoScroll(gesture->details().scroll_y());
293 } 295 }
294 } 296 }
295 297
296 aura::Window* container_; 298 aura::Window* container_;
299 aura::Window::Windows windows_;
297 WindowOverviewModeDelegate* delegate_; 300 WindowOverviewModeDelegate* delegate_;
298 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 301 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
299 302
300 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 303 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
301 }; 304 };
302 305
303 } // namespace 306 } // namespace
304 307
305 // static 308 // static
306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 309 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
307 aura::Window* container, 310 aura::Window* container,
311 const aura::Window::Windows& windows,
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, windows, delegate));
311 } 315 }
312 316
313 } // namespace athena 317 } // namespace athena
OLDNEW
« athena/main/athena_main.cc ('K') | « athena/wm/window_overview_mode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698