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

Roughed in CaptionBar.

Implementing custom caption bar as there will likely be motion specs
requiring unique animation.

Close button not currently wired up.
Demo in bug.

Also fixed a height issue with DialogPlate.

Bug: b:79440488
Change-Id: I6eecff9c48c231e1b1d8aaea026baca09979b7ca
Reviewed-on: https://chromium-review.googlesource.com/1062185Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#559369}
parent 995d4025
...@@ -108,6 +108,8 @@ component("ash") { ...@@ -108,6 +108,8 @@ component("ash") {
"assistant/ui/assistant_bubble.h", "assistant/ui/assistant_bubble.h",
"assistant/ui/assistant_bubble_view.cc", "assistant/ui/assistant_bubble_view.cc",
"assistant/ui/assistant_bubble_view.h", "assistant/ui/assistant_bubble_view.h",
"assistant/ui/caption_bar.cc",
"assistant/ui/caption_bar.h",
"assistant/ui/dialog_plate/action_view.cc", "assistant/ui/dialog_plate/action_view.cc",
"assistant/ui/dialog_plate/action_view.h", "assistant/ui/dialog_plate/action_view.h",
"assistant/ui/dialog_plate/dialog_plate.cc", "assistant/ui/dialog_plate/dialog_plate.cc",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/assistant/model/assistant_interaction_model.h" #include "ash/assistant/model/assistant_interaction_model.h"
#include "ash/assistant/model/assistant_query.h" #include "ash/assistant/model/assistant_query.h"
#include "ash/assistant/model/assistant_ui_element.h" #include "ash/assistant/model/assistant_ui_element.h"
#include "ash/assistant/ui/caption_bar.h"
#include "ash/assistant/ui/dialog_plate/dialog_plate.h" #include "ash/assistant/ui/dialog_plate/dialog_plate.h"
#include "ash/public/cpp/app_list/answer_card_contents_registry.h" #include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
...@@ -409,6 +410,7 @@ class SuggestionsContainer : public views::View { ...@@ -409,6 +410,7 @@ class SuggestionsContainer : public views::View {
AssistantBubbleView::AssistantBubbleView( AssistantBubbleView::AssistantBubbleView(
AssistantController* assistant_controller) AssistantController* assistant_controller)
: assistant_controller_(assistant_controller), : assistant_controller_(assistant_controller),
caption_bar_(new CaptionBar()),
interaction_container_( interaction_container_(
new InteractionContainer(assistant_controller->interaction_model())), new InteractionContainer(assistant_controller->interaction_model())),
ui_element_container_(new UiElementContainer()), ui_element_container_(new UiElementContainer()),
...@@ -438,26 +440,34 @@ void AssistantBubbleView::ChildPreferredSizeChanged(views::View* child) { ...@@ -438,26 +440,34 @@ void AssistantBubbleView::ChildPreferredSizeChanged(views::View* child) {
} }
void AssistantBubbleView::ChildVisibilityChanged(views::View* child) { void AssistantBubbleView::ChildVisibilityChanged(views::View* child) {
// When toggling the visibility of the dialog plate, we also need to update // When toggling the visibility of the caption bar or dialog plate, we also
// the bottom padding of the layout. // need to update the padding of the layout.
if (child == dialog_plate_) { if (child == caption_bar_ || child == dialog_plate_) {
const int padding_top_dip = caption_bar_->visible() ? 0 : kPaddingDip;
const int padding_bottom_dip = dialog_plate_->visible() ? 0 : kPaddingDip; const int padding_bottom_dip = dialog_plate_->visible() ? 0 : kPaddingDip;
layout_manager_->set_inside_border_insets( layout_manager_->set_inside_border_insets(
gfx::Insets(kPaddingDip, 0, padding_bottom_dip, 0)); gfx::Insets(padding_top_dip, 0, padding_bottom_dip, 0));
} }
PreferredSizeChanged(); PreferredSizeChanged();
} }
void AssistantBubbleView::InitLayout() { void AssistantBubbleView::InitLayout() {
// Dialog plate is not visible when using the stylus input modality. // Caption bar and dialog plate are not visible when using stylus modality.
const bool show_dialog_plate = const bool is_using_stylus =
assistant_controller_->interaction_model()->input_modality() != assistant_controller_->interaction_model()->input_modality() ==
InputModality::kStylus; InputModality::kStylus;
// There should be no vertical padding on the layout when the caption bar
// and dialog plate are present.
const int padding_vertical_dip = is_using_stylus ? kPaddingDip : 0;
layout_manager_ = SetLayoutManager(std::make_unique<views::BoxLayout>( layout_manager_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical, views::BoxLayout::Orientation::kVertical,
gfx::Insets(kPaddingDip, 0, show_dialog_plate ? 0 : kPaddingDip, 0), gfx::Insets(padding_vertical_dip, 0), kSpacingDip));
kSpacingDip));
// Caption bar.
caption_bar_->SetVisible(!is_using_stylus);
AddChildView(caption_bar_);
// Interaction container. // Interaction container.
AddChildView(interaction_container_); AddChildView(interaction_container_);
...@@ -471,7 +481,7 @@ void AssistantBubbleView::InitLayout() { ...@@ -471,7 +481,7 @@ void AssistantBubbleView::InitLayout() {
AddChildView(suggestions_container_); AddChildView(suggestions_container_);
// Dialog plate. // Dialog plate.
dialog_plate_->SetVisible(show_dialog_plate); dialog_plate_->SetVisible(!is_using_stylus);
AddChildView(dialog_plate_); AddChildView(dialog_plate_);
} }
...@@ -497,7 +507,8 @@ void AssistantBubbleView::ProcessPendingUiElements() { ...@@ -497,7 +507,8 @@ void AssistantBubbleView::ProcessPendingUiElements() {
} }
void AssistantBubbleView::OnInputModalityChanged(InputModality input_modality) { void AssistantBubbleView::OnInputModalityChanged(InputModality input_modality) {
// Dialog plate is not visible when using stylus input modality. // Caption bar and dialog plate are not visible when using stylus modality.
caption_bar_->SetVisible(input_modality != InputModality::kStylus);
dialog_plate_->SetVisible(input_modality != InputModality::kStylus); dialog_plate_->SetVisible(input_modality != InputModality::kStylus);
// If the query for the interaction is empty, we may need to update the prompt // If the query for the interaction is empty, we may need to update the prompt
......
...@@ -79,6 +79,7 @@ class AssistantBubbleView : public views::View, ...@@ -79,6 +79,7 @@ class AssistantBubbleView : public views::View,
void OnTextAdded(const AssistantTextElement* text_element); void OnTextAdded(const AssistantTextElement* text_element);
AssistantController* assistant_controller_; // Owned by Shell. AssistantController* assistant_controller_; // Owned by Shell.
views::View* caption_bar_; // Owned by view hierarchy.
InteractionContainer* interaction_container_; // Owned by view hierarchy. InteractionContainer* interaction_container_; // Owned by view hierarchy.
UiElementContainer* ui_element_container_; // Owned by view hierarchy. UiElementContainer* ui_element_container_; // Owned by view hierarchy.
SuggestionsContainer* suggestions_container_; // Owned by view hierarchy. SuggestionsContainer* suggestions_container_; // Owned by view hierarchy.
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/assistant/ui/caption_bar.h"
#include "ash/public/cpp/vector_icons/vector_icons.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/background.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h"
namespace ash {
namespace {
// Appearance.
constexpr int kIconSizeDip = 24;
constexpr int kPaddingDip = 14;
constexpr int kPreferredHeightDip = 48;
constexpr int kWindowControlSizeDip = 12;
} // namespace
CaptionBar::CaptionBar() {
InitLayout();
}
CaptionBar::~CaptionBar() = default;
gfx::Size CaptionBar::CalculatePreferredSize() const {
return gfx::Size(INT_MAX, GetHeightForWidth(INT_MAX));
}
int CaptionBar::GetHeightForWidth(int width) const {
return kPreferredHeightDip;
}
void CaptionBar::InitLayout() {
views::BoxLayout* layout_manager =
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal,
gfx::Insets(0, kPaddingDip)));
layout_manager->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::CROSS_AXIS_ALIGNMENT_CENTER);
// Icon.
views::ImageView* icon_view = new views::ImageView();
icon_view->SetImage(gfx::CreateVectorIcon(kAssistantIcon, kIconSizeDip));
icon_view->SetImageSize(gfx::Size(kIconSizeDip, kIconSizeDip));
icon_view->SetPreferredSize(gfx::Size(kIconSizeDip, kIconSizeDip));
AddChildView(icon_view);
// Spacer.
views::View* spacer = new views::View();
AddChildView(spacer);
layout_manager->SetFlexForView(spacer, 1);
// TODO(dmblack): Handle close button.
// Close.
views::ImageView* close_view = new views::ImageView();
close_view->SetImage(gfx::CreateVectorIcon(
kWindowControlCloseIcon, kWindowControlSizeDip, gfx::kGoogleGrey700));
close_view->SetImageSize(
gfx::Size(kWindowControlSizeDip, kWindowControlSizeDip));
close_view->SetPreferredSize(
gfx::Size(kWindowControlSizeDip, kWindowControlSizeDip));
AddChildView(close_view);
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_ASSISTANT_UI_CAPTION_BAR_H_
#define ASH_ASSISTANT_UI_CAPTION_BAR_H_
#include "base/macros.h"
#include "ui/views/view.h"
namespace ash {
class CaptionBar : public views::View {
public:
CaptionBar();
~CaptionBar() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override;
private:
void InitLayout();
DISALLOW_COPY_AND_ASSIGN(CaptionBar);
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_CAPTION_BAR_H_
...@@ -53,7 +53,11 @@ DialogPlate::~DialogPlate() { ...@@ -53,7 +53,11 @@ DialogPlate::~DialogPlate() {
} }
gfx::Size DialogPlate::CalculatePreferredSize() const { gfx::Size DialogPlate::CalculatePreferredSize() const {
return gfx::Size(INT_MAX, kPreferredHeightDip); return gfx::Size(INT_MAX, GetHeightForWidth(INT_MAX));
}
int DialogPlate::GetHeightForWidth(int width) const {
return kPreferredHeightDip;
} }
void DialogPlate::InitLayout() { void DialogPlate::InitLayout() {
......
...@@ -25,6 +25,7 @@ class DialogPlate : public views::View, ...@@ -25,6 +25,7 @@ class DialogPlate : public views::View,
// views::View: // views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override;
void RequestFocus() override; void RequestFocus() override;
// views::TextfieldController: // views::TextfieldController:
......
...@@ -9,6 +9,7 @@ aggregate_vector_icons("ash_vector_icons") { ...@@ -9,6 +9,7 @@ aggregate_vector_icons("ash_vector_icons") {
icon_directory = "." icon_directory = "."
icons = [ icons = [
"assistant.icon",
"captive_portal.icon", "captive_portal.icon",
"check_circle.icon", "check_circle.icon",
"circle.icon", "circle.icon",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 192,
PATH_COLOR_ARGB, 0xFF, 0x34, 0xA8, 0x53,
CIRCLE, 172, 60, 12,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0xEA, 0x43, 0x35,
CIRCLE, 136, 88, 24,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0xFB, 0xBC, 0x05,
CIRCLE, 136, 148, 28,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0x42, 0x85, 0xF4,
CIRCLE, 56, 64, 48
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