Commit 5abe053b authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Remove SchedulePaintType enum

SchedulePaintType was used to only argument of a function.
and it has only two values. so it is possible change to bool arg.
the change will make more shorter code at overall.
and inlining all of BoundsChanged() into SetBoundsRect()
to make this code clearer.

Bug: 940736
Change-Id: I14bd47155aef0e71c9c17f9fd693901f1bd2bd0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1530504Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Cr-Commit-Position: refs/heads/master@{#645376}
parent fd30af34
...@@ -235,16 +235,66 @@ void View::SetBoundsRect(const gfx::Rect& bounds) { ...@@ -235,16 +235,66 @@ void View::SetBoundsRect(const gfx::Rect& bounds) {
return; return;
} }
if (visible_) { bool is_size_changed = bounds_.size() != bounds.size();
// Paint where the view is currently. // Paint where the view is currently.
SchedulePaintBoundsChanged( SchedulePaintBoundsChanged(is_size_changed);
bounds_.size() == bounds.size() ? SCHEDULE_PAINT_SIZE_SAME :
SCHEDULE_PAINT_SIZE_CHANGED);
}
gfx::Rect prev = bounds_; gfx::Rect prev = bounds_;
bounds_ = bounds; bounds_ = bounds;
BoundsChanged(prev);
// Paint the new bounds.
SchedulePaintBoundsChanged(is_size_changed);
if (layer()) {
if (parent_) {
LayerOffsetData offset_data(
parent_->CalculateOffsetToAncestorWithLayer(nullptr));
offset_data += GetMirroredPosition().OffsetFromOrigin();
SetLayerBounds(size(), offset_data);
} else {
SetLayerBounds(bounds_.size(),
LayerOffsetData() + bounds_.OffsetFromOrigin());
}
// In RTL mode, if our width has changed, our children's mirrored bounds
// will have changed. Update the child's layer bounds, or if it is not a
// layer, the bounds of any layers inside the child.
if (base::i18n::IsRTL() && bounds_.width() != prev.width()) {
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
child->UpdateChildLayerBounds(
LayerOffsetData(layer()->device_scale_factor(),
child->GetMirroredPosition().OffsetFromOrigin()));
}
}
} else {
// If our bounds have changed, then any descendant layer bounds may have
// changed. Update them accordingly.
UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(nullptr));
}
OnBoundsChanged(prev);
if (bounds_ != prev)
NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged, false);
if (needs_layout_ || is_size_changed) {
needs_layout_ = false;
TRACE_EVENT1("views", "View::Layout(bounds_changed)", "class",
GetClassName());
Layout();
}
if (GetNeedsNotificationWhenVisibleBoundsChange())
OnVisibleBoundsChanged();
// Notify interested Views that visible bounds within the root view may have
// changed.
if (descendants_to_notify_) {
for (auto i(descendants_to_notify_->begin());
i != descendants_to_notify_->end(); ++i) {
(*i)->OnVisibleBoundsChanged();
}
}
for (ViewObserver& observer : observers_) for (ViewObserver& observer : observers_)
observer.OnViewBoundsChanged(this); observer.OnViewBoundsChanged(this);
...@@ -1808,15 +1858,18 @@ void View::DragInfo::PossibleDrag(const gfx::Point& p) { ...@@ -1808,15 +1858,18 @@ void View::DragInfo::PossibleDrag(const gfx::Point& p) {
// Painting -------------------------------------------------------------------- // Painting --------------------------------------------------------------------
void View::SchedulePaintBoundsChanged(SchedulePaintType type) { void View::SchedulePaintBoundsChanged(bool size_changed) {
if (!visible_)
return;
// If we have a layer and the View's size did not change, we do not need to // If we have a layer and the View's size did not change, we do not need to
// schedule any paints since the layer will be redrawn at its new location // schedule any paints since the layer will be redrawn at its new location
// during the next Draw() cycle in the compositor. // during the next Draw() cycle in the compositor.
if (!layer() || type == SCHEDULE_PAINT_SIZE_CHANGED) { if (!layer() || size_changed) {
// Otherwise, if the size changes or we don't have a layer then we need to // Otherwise, if the size changes or we don't have a layer then we need to
// use SchedulePaint to invalidate the area occupied by the View. // use SchedulePaint to invalidate the area occupied by the View.
SchedulePaint(); SchedulePaint();
} else if (parent_ && type == SCHEDULE_PAINT_SIZE_SAME) { } else {
// The compositor doesn't Draw() until something on screen changes, so // The compositor doesn't Draw() until something on screen changes, so
// if our position changes but nothing is being animated on screen, then // if our position changes but nothing is being animated on screen, then
// tell the compositor to redraw the scene. We know layer() exists due to // tell the compositor to redraw the scene. We know layer() exists due to
...@@ -2155,66 +2208,6 @@ void View::SnapLayerToPixelBoundary(const LayerOffsetData& offset_data) { ...@@ -2155,66 +2208,6 @@ void View::SnapLayerToPixelBoundary(const LayerOffsetData& offset_data) {
} }
} }
void View::BoundsChanged(const gfx::Rect& previous_bounds) {
if (visible_) {
// Paint the new bounds.
SchedulePaintBoundsChanged(
bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME :
SCHEDULE_PAINT_SIZE_CHANGED);
}
if (layer()) {
if (parent_) {
LayerOffsetData offset_data(
parent_->CalculateOffsetToAncestorWithLayer(nullptr));
offset_data += GetMirroredPosition().OffsetFromOrigin();
SetLayerBounds(size(), offset_data);
} else {
SetLayerBounds(bounds_.size(),
LayerOffsetData() + bounds_.OffsetFromOrigin());
}
// In RTL mode, if our width has changed, our children's mirrored bounds
// will have changed. Update the child's layer bounds, or if it is not a
// layer, the bounds of any layers inside the child.
if (base::i18n::IsRTL() && bounds_.width() != previous_bounds.width()) {
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
child->UpdateChildLayerBounds(
LayerOffsetData(layer()->device_scale_factor(),
child->GetMirroredPosition().OffsetFromOrigin()));
}
}
} else {
// If our bounds have changed, then any descendant layer bounds may have
// changed. Update them accordingly.
UpdateChildLayerBounds(CalculateOffsetToAncestorWithLayer(nullptr));
}
OnBoundsChanged(previous_bounds);
if (bounds_ != previous_bounds)
NotifyAccessibilityEvent(ax::mojom::Event::kLocationChanged, false);
if (needs_layout_ || previous_bounds.size() != size()) {
needs_layout_ = false;
TRACE_EVENT1("views", "View::Layout(bounds_changed)", "class",
GetClassName());
Layout();
}
if (GetNeedsNotificationWhenVisibleBoundsChange())
OnVisibleBoundsChanged();
// Notify interested Views that visible bounds within the root view may have
// changed.
if (descendants_to_notify_) {
for (auto i(descendants_to_notify_->begin());
i != descendants_to_notify_->end(); ++i) {
(*i)->OnVisibleBoundsChanged();
}
}
}
// static // static
void View::RegisterChildrenForVisibleBoundsNotification(View* view) { void View::RegisterChildrenForVisibleBoundsNotification(View* view) {
if (view->GetNeedsNotificationWhenVisibleBoundsChange()) if (view->GetNeedsNotificationWhenVisibleBoundsChange())
......
...@@ -1439,17 +1439,9 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -1439,17 +1439,9 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// Painting ----------------------------------------------------------------- // Painting -----------------------------------------------------------------
enum SchedulePaintType {
// Indicates the size is the same (only the origin changed).
SCHEDULE_PAINT_SIZE_SAME,
// Indicates the size changed (and possibly the origin).
SCHEDULE_PAINT_SIZE_CHANGED
};
// Invoked before and after the bounds change to schedule painting the old and // Invoked before and after the bounds change to schedule painting the old and
// new bounds. // new bounds.
void SchedulePaintBoundsChanged(SchedulePaintType type); void SchedulePaintBoundsChanged(bool size_changed);
// Schedules a paint on the parent View if it exists. // Schedules a paint on the parent View if it exists.
void SchedulePaintOnParent(); void SchedulePaintOnParent();
...@@ -1535,10 +1527,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, ...@@ -1535,10 +1527,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// VisibilityChanged(). // VisibilityChanged().
void VisibilityChangedImpl(View* starting_from, bool is_visible); void VisibilityChangedImpl(View* starting_from, bool is_visible);
// Responsible for propagating bounds change notifications to relevant
// views.
void BoundsChanged(const gfx::Rect& previous_bounds);
// Visible bounds notification registration. // Visible bounds notification registration.
// When a view is added to a hierarchy, it and all its children are asked if // When a view is added to a hierarchy, it and all its children are asked if
// they need to be registered for "visible bounds within root" notifications // they need to be registered for "visible bounds within root" notifications
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment