blob: 4280cc575714b1221f1185d6847084102ca61605 [file] [log] [blame]
// 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_ASSISTANT_MINI_VIEW_H_
#define ASH_ASSISTANT_UI_ASSISTANT_MINI_VIEW_H_
#include <memory>
#include <string>
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "base/component_export.h"
#include "base/macros.h"
#include "base/optional.h"
#include "ui/views/controls/button/button.h"
namespace views {
class Label;
} // namespace views
namespace ash {
class AssistantViewDelegate;
// AssistantMiniViewDelegate ---------------------------------------------------
// TODO(wutao): Remove this class and call methods on AssistantViewDelegate
// derectly.
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantMiniViewDelegate {
public:
// Invoked when the AssistantMiniView is pressed.
virtual void OnAssistantMiniViewPressed() {}
protected:
virtual ~AssistantMiniViewDelegate() = default;
};
// AssistantMiniView -----------------------------------------------------------
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantMiniView
: public views::Button,
public views::ButtonListener,
public AssistantInteractionModelObserver,
public AssistantUiModelObserver {
public:
explicit AssistantMiniView(AssistantViewDelegate* delegate);
~AssistantMiniView() override;
// views::View:
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
int GetHeightForWidth(int width) const override;
void ChildPreferredSizeChanged(views::View* child) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// AssistantInteractionModelObserver:
void OnInputModalityChanged(InputModality input_modality) override;
void OnResponseChanged(
const std::shared_ptr<AssistantResponse>& response) override;
// AssistantUiModelObserver:
void OnUiVisibilityChanged(
AssistantVisibility new_visibility,
AssistantVisibility old_visibility,
base::Optional<AssistantEntryPoint> entry_point,
base::Optional<AssistantExitPoint> exit_point) override;
void set_mini_view_delegate(AssistantMiniViewDelegate* delegate) {
mini_view_delegate_ = delegate;
}
private:
void InitLayout();
void UpdatePrompt();
AssistantViewDelegate* const delegate_;
views::Label* label_; // Owned by view hierarchy.
AssistantMiniViewDelegate* mini_view_delegate_ = nullptr;
// The most recent active query for the current Assistant UI session. If there
// has been no active query for the current UI session, this is empty.
base::Optional<std::string> last_active_query_;
DISALLOW_COPY_AND_ASSIGN(AssistantMiniView);
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_ASSISTANT_MINI_VIEW_H_