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

Side by Side Diff: cc/trees/layer_tree_impl.cc

Issue 901813002: Normalize top controls offset to (0, 1), Chromium-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include <algorithm>
7 #include <limits> 8 #include <limits>
8 #include <set> 9 #include <set>
9 10
10 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_argument.h" 12 #include "base/trace_event/trace_event_argument.h"
12 #include "cc/animation/keyframed_animation_curve.h" 13 #include "cc/animation/keyframed_animation_curve.h"
13 #include "cc/animation/scrollbar_animation_controller.h" 14 #include "cc/animation/scrollbar_animation_controller.h"
14 #include "cc/animation/scrollbar_animation_controller_linear_fade.h" 15 #include "cc/animation/scrollbar_animation_controller_linear_fade.h"
15 #include "cc/animation/scrollbar_animation_controller_thinning.h" 16 #include "cc/animation/scrollbar_animation_controller_thinning.h"
16 #include "cc/base/math_util.h" 17 #include "cc/base/math_util.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 private: 70 private:
70 LayerImpl* layer_; 71 LayerImpl* layer_;
71 LayerScrollOffsetDelegate* delegate_; 72 LayerScrollOffsetDelegate* delegate_;
72 LayerTreeImpl* layer_tree_impl_; 73 LayerTreeImpl* layer_tree_impl_;
73 gfx::ScrollOffset last_set_scroll_offset_; 74 gfx::ScrollOffset last_set_scroll_offset_;
74 }; 75 };
75 76
76 LayerTreeImpl::LayerTreeImpl( 77 LayerTreeImpl::LayerTreeImpl(
77 LayerTreeHostImpl* layer_tree_host_impl, 78 LayerTreeHostImpl* layer_tree_host_impl,
78 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, 79 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
80 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
79 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) 81 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll)
80 : layer_tree_host_impl_(layer_tree_host_impl), 82 : layer_tree_host_impl_(layer_tree_host_impl),
81 source_frame_number_(-1), 83 source_frame_number_(-1),
82 hud_layer_(0), 84 hud_layer_(0),
83 currently_scrolling_layer_(NULL), 85 currently_scrolling_layer_(NULL),
84 root_layer_scroll_offset_delegate_(NULL), 86 root_layer_scroll_offset_delegate_(NULL),
85 background_color_(0), 87 background_color_(0),
86 has_transparent_background_(false), 88 has_transparent_background_(false),
87 overscroll_elasticity_layer_(NULL), 89 overscroll_elasticity_layer_(NULL),
88 page_scale_layer_(NULL), 90 page_scale_layer_(NULL),
89 inner_viewport_scroll_layer_(NULL), 91 inner_viewport_scroll_layer_(NULL),
90 outer_viewport_scroll_layer_(NULL), 92 outer_viewport_scroll_layer_(NULL),
91 page_scale_factor_(page_scale_factor), 93 page_scale_factor_(page_scale_factor),
92 min_page_scale_factor_(0), 94 min_page_scale_factor_(0),
93 max_page_scale_factor_(0), 95 max_page_scale_factor_(0),
94 elastic_overscroll_(elastic_overscroll), 96 elastic_overscroll_(elastic_overscroll),
95 scrolling_layer_id_from_previous_tree_(0), 97 scrolling_layer_id_from_previous_tree_(0),
96 contents_textures_purged_(false), 98 contents_textures_purged_(false),
97 viewport_size_invalid_(false), 99 viewport_size_invalid_(false),
98 needs_update_draw_properties_(true), 100 needs_update_draw_properties_(true),
99 needs_full_tree_sync_(true), 101 needs_full_tree_sync_(true),
100 next_activation_forces_redraw_(false), 102 next_activation_forces_redraw_(false),
101 has_ever_been_drawn_(false), 103 has_ever_been_drawn_(false),
102 render_surface_layer_list_id_(0), 104 render_surface_layer_list_id_(0),
103 top_controls_shrink_blink_size_(false), 105 top_controls_shrink_blink_size_(false),
104 top_controls_height_(0), 106 top_controls_height_(0),
105 top_controls_content_offset_(0), 107 top_controls_shown_ratio_(top_controls_shown_ratio) {
106 top_controls_delta_(0),
107 sent_top_controls_delta_(0) {
108 } 108 }
109 109
110 LayerTreeImpl::~LayerTreeImpl() { 110 LayerTreeImpl::~LayerTreeImpl() {
111 BreakSwapPromises(SwapPromise::SWAP_FAILS); 111 BreakSwapPromises(SwapPromise::SWAP_FAILS);
112 112
113 // Need to explicitly clear the tree prior to destroying this so that 113 // Need to explicitly clear the tree prior to destroying this so that
114 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. 114 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
115 DCHECK(!root_layer_); 115 DCHECK(!root_layer_);
116 DCHECK(layers_with_copy_output_request_.empty()); 116 DCHECK(layers_with_copy_output_request_.empty());
117 } 117 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // The request queue should have been processed and does not require a push. 198 // The request queue should have been processed and does not require a push.
199 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); 199 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
200 200
201 if (next_activation_forces_redraw_) { 201 if (next_activation_forces_redraw_) {
202 target_tree->ForceRedrawNextActivation(); 202 target_tree->ForceRedrawNextActivation();
203 next_activation_forces_redraw_ = false; 203 next_activation_forces_redraw_ = false;
204 } 204 }
205 205
206 target_tree->PassSwapPromises(&swap_promise_list_); 206 target_tree->PassSwapPromises(&swap_promise_list_);
207 207
208 // Track the change in top controls height to offset the top_controls_delta 208 target_tree->set_top_controls_shrink_blink_size(
209 // properly. This is so that the top controls offset will be maintained 209 top_controls_shrink_blink_size_);
210 // across height changes. 210 target_tree->set_top_controls_height(top_controls_height_);
211 float top_controls_height_delta = 211 target_tree->PushTopControls(nullptr);
212 target_tree->top_controls_height_ - top_controls_height_;
213
214 target_tree->top_controls_shrink_blink_size_ =
215 top_controls_shrink_blink_size_;
216 target_tree->top_controls_height_ = top_controls_height_;
217 target_tree->top_controls_content_offset_ = top_controls_content_offset_;
218 target_tree->top_controls_delta_ = target_tree->top_controls_delta_ -
219 target_tree->sent_top_controls_delta_ -
220 top_controls_height_delta;
221 target_tree->sent_top_controls_delta_ = 0.f;
222 212
223 // Active tree already shares the page_scale_factor object with pending 213 // Active tree already shares the page_scale_factor object with pending
224 // tree so only the limits need to be provided. 214 // tree so only the limits need to be provided.
225 target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(), 215 target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(),
226 max_page_scale_factor()); 216 max_page_scale_factor());
227 target_tree->elastic_overscroll()->PushPendingToActive(); 217 target_tree->elastic_overscroll()->PushPendingToActive();
228 218
229 target_tree->pending_page_scale_animation_ = 219 target_tree->pending_page_scale_animation_ =
230 pending_page_scale_animation_.Pass(); 220 pending_page_scale_animation_.Pass();
231 221
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 342 }
353 if (IsActiveTree()) 343 if (IsActiveTree())
354 changed_page_scale |= page_scale_factor_->PushPendingToActive(); 344 changed_page_scale |= page_scale_factor_->PushPendingToActive();
355 changed_page_scale |= 345 changed_page_scale |=
356 SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor); 346 SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor);
357 347
358 if (changed_page_scale) 348 if (changed_page_scale)
359 DidUpdatePageScale(); 349 DidUpdatePageScale();
360 } 350 }
361 351
352 void LayerTreeImpl::set_top_controls_shrink_blink_size(bool shrink) {
353 if (top_controls_shrink_blink_size_ == shrink)
354 return;
355
356 top_controls_shrink_blink_size_ = shrink;
357 if (IsActiveTree())
358 layer_tree_host_impl_->UpdateViewportContainerSizes();
359 }
360
361 void LayerTreeImpl::set_top_controls_height(float top_controls_height) {
362 if (top_controls_height_ == top_controls_height)
363 return;
364
365 top_controls_height_ = top_controls_height;
366 if (IsActiveTree())
367 layer_tree_host_impl_->UpdateViewportContainerSizes();
368 }
369
370 bool LayerTreeImpl::SetCurrentTopControlsShownRatio(float ratio) {
371 ratio = std::max(ratio, 0.f);
372 ratio = std::min(ratio, 1.f);
373 return top_controls_shown_ratio_->SetCurrent(ratio);
374 }
375
376 void LayerTreeImpl::PushTopControlsFromMainThread(
377 float top_controls_shown_ratio) {
378 PushTopControls(&top_controls_shown_ratio);
379 }
380
381 void LayerTreeImpl::PushTopControls(const float* top_controls_shown_ratio) {
382 DCHECK(top_controls_shown_ratio || IsActiveTree());
383
384 if (top_controls_shown_ratio) {
385 DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree());
386 top_controls_shown_ratio_->PushFromMainThread(*top_controls_shown_ratio);
387 }
388 if (IsActiveTree()) {
389 if (top_controls_shown_ratio_->PushPendingToActive())
390 layer_tree_host_impl_->DidChangeTopControlsPosition();
391 }
392 }
393
362 bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor, 394 bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor,
363 float max_page_scale_factor) { 395 float max_page_scale_factor) {
364 if (min_page_scale_factor == min_page_scale_factor_ && 396 if (min_page_scale_factor == min_page_scale_factor_ &&
365 max_page_scale_factor == max_page_scale_factor_) 397 max_page_scale_factor == max_page_scale_factor_)
366 return false; 398 return false;
367 399
368 min_page_scale_factor_ = min_page_scale_factor; 400 min_page_scale_factor_ = min_page_scale_factor;
369 max_page_scale_factor_ = max_page_scale_factor; 401 max_page_scale_factor_ = max_page_scale_factor;
370 402
371 return true; 403 return true;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 } 471 }
440 472
441 static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { 473 static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
442 layer->ApplySentScrollDeltasFromAbortedCommit(); 474 layer->ApplySentScrollDeltasFromAbortedCommit();
443 } 475 }
444 476
445 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { 477 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
446 DCHECK(IsActiveTree()); 478 DCHECK(IsActiveTree());
447 479
448 page_scale_factor()->AbortCommit(); 480 page_scale_factor()->AbortCommit();
481 top_controls_shown_ratio()->AbortCommit();
449 elastic_overscroll()->AbortCommit(); 482 elastic_overscroll()->AbortCommit();
450 483
451 top_controls_content_offset_ += sent_top_controls_delta_;
452 top_controls_delta_ -= sent_top_controls_delta_;
453 sent_top_controls_delta_ = 0.f;
454
455 if (!root_layer()) 484 if (!root_layer())
456 return; 485 return;
457 486
458 LayerTreeHostCommon::CallFunctionForSubtree( 487 LayerTreeHostCommon::CallFunctionForSubtree(
459 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); 488 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
460 } 489 }
461 490
462 void LayerTreeImpl::SetViewportLayersFromIds( 491 void LayerTreeImpl::SetViewportLayersFromIds(
463 int overscroll_elasticity_layer_id, 492 int overscroll_elasticity_layer_id,
464 int page_scale_layer_id, 493 int page_scale_layer_id,
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 scoped_ptr<PendingPageScaleAnimation> pending_animation) { 1579 scoped_ptr<PendingPageScaleAnimation> pending_animation) {
1551 pending_page_scale_animation_ = pending_animation.Pass(); 1580 pending_page_scale_animation_ = pending_animation.Pass();
1552 } 1581 }
1553 1582
1554 scoped_ptr<PendingPageScaleAnimation> 1583 scoped_ptr<PendingPageScaleAnimation>
1555 LayerTreeImpl::TakePendingPageScaleAnimation() { 1584 LayerTreeImpl::TakePendingPageScaleAnimation() {
1556 return pending_page_scale_animation_.Pass(); 1585 return pending_page_scale_animation_.Pass();
1557 } 1586 }
1558 1587
1559 } // namespace cc 1588 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698