Commit 15e92a73 authored by David Black's avatar David Black Committed by Commit Bot

Add top margin to first card in UiElementContainerView.

Per the spec, the first card element should have a top margin of 40dip.

See bug for spec/screenshots.

Bug: b:113611382
Change-Id: I323bc7283db600e1f1e319652715b572583a6fbe
Reviewed-on: https://chromium-review.googlesource.com/1185878Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#587911}
parent 12ceb0f2
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_sink.h" #include "ui/events/event_sink.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/views/border.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -37,6 +38,7 @@ namespace ash { ...@@ -37,6 +38,7 @@ namespace ash {
namespace { namespace {
// Appearance. // Appearance.
constexpr int kFirstCardMarginTopDip = 40;
constexpr int kPaddingHorizontalDip = 32; constexpr int kPaddingHorizontalDip = 32;
// Card element animation. // Card element animation.
...@@ -160,8 +162,17 @@ class CardElementViewHolder : public views::NativeViewHost, ...@@ -160,8 +162,17 @@ class CardElementViewHolder : public views::NativeViewHost,
// views::ViewObserver: // views::ViewObserver:
void OnViewPreferredSizeChanged(views::View* view) override { void OnViewPreferredSizeChanged(views::View* view) override {
contents_view_->SetPreferredSize(view->GetPreferredSize()); gfx::Size preferred_size = view->GetPreferredSize();
SetPreferredSize(view->GetPreferredSize());
if (border()) {
// When a border is present we need to explicitly account for it in our
// size calculations by enlarging our preferred size by the border insets.
const gfx::Insets insets = border()->GetInsets();
preferred_size.Enlarge(insets.width(), insets.height());
}
contents_view_->SetPreferredSize(preferred_size);
SetPreferredSize(preferred_size);
} }
void Attach() { void Attach() {
...@@ -303,6 +314,9 @@ void UiElementContainerView::OnResponseCleared() { ...@@ -303,6 +314,9 @@ void UiElementContainerView::OnResponseCleared() {
// We can clear any pending UI elements as they are no longer relevant. // We can clear any pending UI elements as they are no longer relevant.
pending_ui_element_list_.clear(); pending_ui_element_list_.clear();
SetProcessingUiElement(false); SetProcessingUiElement(false);
// Reset state for the next response.
is_first_card_ = true;
} }
void UiElementContainerView::OnResponseAdded( void UiElementContainerView::OnResponseAdded(
...@@ -433,6 +447,20 @@ void UiElementContainerView::OnCardReady( ...@@ -433,6 +447,20 @@ void UiElementContainerView::OnCardReady(
app_list::AnswerCardContentsRegistry::Get()->GetView( app_list::AnswerCardContentsRegistry::Get()->GetView(
embed_token.value())); embed_token.value()));
if (is_first_card_) {
is_first_card_ = false;
// The first card requires a top margin of |kFirstCardMarginTopDip|, but
// we need to account for child spacing because the first card is not
// necessarily the first UI element.
const int top_margin_dip = child_count() == 0
? kFirstCardMarginTopDip
: kFirstCardMarginTopDip - kSpacingDip;
// We effectively create a top margin by applying an empty border.
view_holder->SetBorder(views::CreateEmptyBorder(top_margin_dip, 0, 0, 0));
}
content_view()->AddChildView(view_holder); content_view()->AddChildView(view_holder);
view_holder->Attach(); view_holder->Attach();
......
...@@ -88,6 +88,10 @@ class UiElementContainerView : public AssistantScrollView, ...@@ -88,6 +88,10 @@ class UiElementContainerView : public AssistantScrollView,
std::unique_ptr<ui::CallbackLayerAnimationObserver> std::unique_ptr<ui::CallbackLayerAnimationObserver>
ui_elements_exit_animation_observer_; ui_elements_exit_animation_observer_;
// Whether or not the card we are adding is the first card for the current
// Assistant response. The first card requires the addition of a top margin.
bool is_first_card_ = true;
// Weak pointer factory used for card rendering requests. // Weak pointer factory used for card rendering requests.
base::WeakPtrFactory<UiElementContainerView> render_request_weak_factory_; base::WeakPtrFactory<UiElementContainerView> render_request_weak_factory_;
......
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