Commit a7f9400c authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOs Status Area: Use a bit mask to keep track of child visibility

The current code makes the assumption that only one child changes
visibility at a time. While this is generally true, there is no actual
guarantee for it. This change keeps track of what children are visible
individually.

Change-Id: Ibc51535c6e0e7e6ab7e167999800138ebc67471b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131038
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755238}
parent b84b5e08
......@@ -424,12 +424,14 @@ void StatusAreaWidget::AddTrayButton(TrayBackgroundView* tray_button) {
}
StatusAreaWidget::LayoutInputs StatusAreaWidget::GetLayoutInputs() const {
unsigned int number_of_visible_children = 0;
for (auto* child : tray_buttons_)
number_of_visible_children += child->GetVisible() ? 1 : 0;
long child_visibility_bitmask = 0;
DCHECK(tray_buttons_.size() <
std::numeric_limits<decltype(child_visibility_bitmask)>::digits);
for (unsigned int i = 0; i < tray_buttons_.size(); ++i)
child_visibility_bitmask |= (tray_buttons_[i]->GetVisible() ? 1 : 0) << i;
return {target_bounds_, CalculateCollapseState(),
shelf_->shelf_layout_manager()->GetOpacity(),
number_of_visible_children};
child_visibility_bitmask};
}
} // namespace ash
......@@ -137,18 +137,13 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver,
gfx::Rect bounds;
CollapseState collapse_state = CollapseState::NOT_COLLAPSIBLE;
float opacity = 0.0f;
// Children change visibility only one at a time, so keeping track of
// how many are visible (as opposed to the visibility state of each) is
// sufficient to make sure we don't miss necessary layout changes.
// TODO(manucornet): The assumption that children only change visibility
// one at a time may be too optimistic. One way to address this would be
// to have a child visibility change counter.
unsigned int number_of_visible_children = 0;
// Each bit keep track of one child's visibility.
long child_visibility_bitmask = 0;
bool operator==(const LayoutInputs& other) const {
return bounds == other.bounds && collapse_state == other.collapse_state &&
opacity == other.opacity &&
number_of_visible_children == other.number_of_visible_children;
child_visibility_bitmask == other.child_visibility_bitmask;
}
};
......
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