Commit a4e8e863 authored by David Black's avatar David Black Committed by Commit Bot

Impose minimum height restrictions.

UX spec dictates that if not in stylus mode:
- Height should be >= 200dip.
- Height should grow to match contents.
- Height should not shrink until Assistant UI is closed.

Note that now UiElementContainerView needs to always be visible so
that it can fill the remaining space, even when empty of children.

Demo in bug.

Bug: b:79432250
Change-Id: I32372467bb8fff2b74885014b34152ce907be1bf
Reviewed-on: https://chromium-review.googlesource.com/1074373
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562594}
parent d2e44900
......@@ -23,8 +23,8 @@ namespace {
// Appearance.
constexpr SkColor kBackgroundColor = SK_ColorWHITE;
constexpr int kCornerRadiusDip = 16;
constexpr int kMarginDip = 16;
constexpr int kCornerRadiusDip = 20;
constexpr int kMarginDip = 8;
// AssistantContainerView ------------------------------------------------------
......
......@@ -27,6 +27,7 @@ namespace {
// Appearance.
constexpr int kIconSizeDip = 32;
constexpr int kMinHeightDip = 200;
constexpr int kMaxHeightDip = 640;
// TODO(b/77638210): Replace with localized resource strings.
......@@ -215,7 +216,8 @@ AssistantBubbleView::AssistantBubbleView(
new InteractionContainer(assistant_controller->interaction_model())),
ui_element_container_(new UiElementContainerView(assistant_controller)),
suggestions_container_(new SuggestionContainerView(assistant_controller)),
dialog_plate_(new DialogPlate(assistant_controller)) {
dialog_plate_(new DialogPlate(assistant_controller)),
min_height_dip_(kMinHeightDip) {
InitLayout();
// Observe changes to interaction model.
......@@ -227,13 +229,35 @@ AssistantBubbleView::~AssistantBubbleView() {
}
gfx::Size AssistantBubbleView::CalculatePreferredSize() const {
int preferred_height =
std::min(GetHeightForWidth(kPreferredWidthDip), kMaxHeightDip);
int preferred_height = GetHeightForWidth(kPreferredWidthDip);
// When not using stylus input modality:
// |min_height_dip_| <= preferred_height <= |kMaxHeightDip|.
if (assistant_controller_->interaction_model()->input_modality() !=
InputModality::kStylus) {
preferred_height =
std::min(std::max(preferred_height, min_height_dip_), kMaxHeightDip);
}
return gfx::Size(kPreferredWidthDip, preferred_height);
}
void AssistantBubbleView::OnBoundsChanged(const gfx::Rect& prev_bounds) {
// Until Assistant UI is hidden, the view may grow in height but not shrink.
// The exception to this rule is if using stylus input modality.
min_height_dip_ = std::max(min_height_dip_, height());
}
void AssistantBubbleView::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged();
// We force a layout here because, though we are receiving a
// ChildPreferredSizeChanged event, it may be that the
// |ui_element_container_|'s bounds will not actually change due to the height
// restrictions imposed by AssistantBubbleView. When this is the case, we
// need to force a layout to see |ui_element_container_|'s new contents.
if (child == ui_element_container_)
Layout();
}
void AssistantBubbleView::ChildVisibilityChanged(views::View* child) {
......@@ -249,7 +273,8 @@ void AssistantBubbleView::ChildVisibilityChanged(views::View* child) {
}
void AssistantBubbleView::InitLayout() {
// Caption bar and dialog plate are not visible when using stylus modality.
// Caption bar, dialog plate, suggestion container, and UI element container
// are not visible when using stylus modality.
const bool is_using_stylus =
assistant_controller_->interaction_model()->input_modality() ==
InputModality::kStylus;
......@@ -270,7 +295,7 @@ void AssistantBubbleView::InitLayout() {
AddChildView(interaction_container_);
// UI element container.
ui_element_container_->SetVisible(false);
ui_element_container_->SetVisible(!is_using_stylus);
AddChildView(ui_element_container_);
layout_manager_->SetFlexForView(ui_element_container_, 1);
......@@ -285,9 +310,12 @@ void AssistantBubbleView::InitLayout() {
}
void AssistantBubbleView::OnInputModalityChanged(InputModality input_modality) {
// Caption bar and dialog plate are not visible when using stylus modality.
// Caption bar, dialog plate, suggestion container, and UI element container
// are not visible when using stylus modality.
caption_bar_->SetVisible(input_modality != InputModality::kStylus);
dialog_plate_->SetVisible(input_modality != InputModality::kStylus);
suggestions_container_->SetVisible(input_modality != InputModality::kStylus);
ui_element_container_->SetVisible(input_modality != InputModality::kStylus);
// If the query for the interaction is empty, we may need to update the prompt
// to reflect the current input modality.
......@@ -296,6 +324,18 @@ void AssistantBubbleView::OnInputModalityChanged(InputModality input_modality) {
}
}
void AssistantBubbleView::OnInteractionStateChanged(
InteractionState interaction_state) {
if (interaction_state != InteractionState::kInactive)
return;
// When the Assistant UI is being hidden we need to reset our minimum height
// restriction so that the default restrictions are restored for the next
// time the view is shown.
min_height_dip_ = kMinHeightDip;
PreferredSizeChanged();
}
void AssistantBubbleView::OnQueryChanged(const AssistantQuery& query) {
interaction_container_->SetQuery(query);
}
......
......@@ -34,10 +34,12 @@ class AssistantBubbleView : public views::View,
gfx::Size CalculatePreferredSize() const override;
void ChildPreferredSizeChanged(views::View* child) override;
void ChildVisibilityChanged(views::View* child) override;
void OnBoundsChanged(const gfx::Rect& prev_bounds) override;
void RequestFocus() override;
// AssistantInteractionModelObserver:
void OnInputModalityChanged(InputModality input_modality) override;
void OnInteractionStateChanged(InteractionState interaction_state) override;
void OnQueryChanged(const AssistantQuery& query) override;
void OnQueryCleared() override;
......@@ -54,6 +56,8 @@ class AssistantBubbleView : public views::View,
views::BoxLayout* layout_manager_ = nullptr; // Owned by view hierarchy.
int min_height_dip_;
DISALLOW_COPY_AND_ASSIGN(AssistantBubbleView);
};
......
......@@ -107,7 +107,6 @@ void UiElementContainerView::OnUiElementsCleared() {
// Prevent any in-flight card rendering requests from returning.
render_request_weak_factory_.InvalidateWeakPtrs();
SetVisible(false);
RemoveAllChildViews(/*delete_children=*/true);
PreferredSizeChanged();
......@@ -160,7 +159,7 @@ void UiElementContainerView::OnCardReady(
}
// TODO(dmblack): Handle Mash case.
SetVisible(true);
PreferredSizeChanged();
// Once the card has been rendered and embedded, we can resume processing
// any UI elements that are in the pending queue.
......@@ -191,7 +190,6 @@ void UiElementContainerView::OnTextElementAdded(
text_container->AddChildView(text_view);
AddChildView(text_container);
SetVisible(true);
PreferredSizeChanged();
}
......
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