Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QA Rich Card: add translation child view
Differentiate between content shown on the rich card view using the quick answer result type. Added the RichAnswersTranslationView class, views for definition and unit conversion will be added next. --gtest_filter=*RichAnswersBrowserTest* --enable-pixel-output-in-tests` Tests: tested on DUT, `out/Default/browser_tests Bug: b/265258270 Change-Id: I2623bd448ebaace97de7fa3a1f973f1456f063a3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4347826 Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org> Commit-Queue: Angela Xiao <angelaxiao@chromium.org> Cr-Commit-Position: refs/heads/main@{#1121416}
- Loading branch information
Angela Xiao
authored and
Chromium LUCI CQ
committed
Mar 23, 2023
1 parent
1553cfa
commit d4bb172
Showing
11 changed files
with
258 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
chrome/browser/ui/quick_answers/ui/rich_answers_translation_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/quick_answers/ui/rich_answers_translation_view.h" | ||
|
||
#include "base/functional/bind.h" | ||
#include "base/memory/raw_ptr.h" | ||
#include "chrome/browser/ui/color/chrome_color_id.h" | ||
#include "chrome/browser/ui/quick_answers/quick_answers_ui_controller.h" | ||
#include "chromeos/components/quick_answers/quick_answers_model.h" | ||
#include "chromeos/strings/grit/chromeos_strings.h" | ||
#include "components/vector_icons/vector_icons.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/color/color_id.h" | ||
#include "ui/color/color_provider.h" | ||
#include "ui/display/screen.h" | ||
#include "ui/gfx/paint_vector_icon.h" | ||
#include "ui/views/accessibility/view_accessibility.h" | ||
#include "ui/views/background.h" | ||
#include "ui/views/border.h" | ||
#include "ui/views/controls/button/button.h" | ||
#include "ui/views/controls/button/button_controller.h" | ||
#include "ui/views/controls/button/image_button.h" | ||
#include "ui/views/controls/image_view.h" | ||
#include "ui/views/layout/fill_layout.h" | ||
#include "ui/views/widget/widget.h" | ||
#include "ui/wm/core/coordinate_conversion.h" | ||
|
||
// RichAnswersTranslationView | ||
// ----------------------------------------------------------- | ||
|
||
RichAnswersTranslationView::RichAnswersTranslationView( | ||
const quick_answers::QuickAnswer& result) { | ||
InitLayout(); | ||
|
||
// Focus. | ||
// We use custom focus behavior for the quick answers views. | ||
// TODO (b/274665781): Add unit tests for focus behavior. | ||
SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | ||
set_suppress_default_focus_handling(); | ||
focus_search_ = std::make_unique<QuickAnswersFocusSearch>( | ||
this, base::BindRepeating(&RichAnswersTranslationView::GetFocusableViews, | ||
base::Unretained(this))); | ||
} | ||
|
||
RichAnswersTranslationView::~RichAnswersTranslationView() = default; | ||
|
||
const char* RichAnswersTranslationView::GetClassName() const { | ||
return "RichAnswersTranslationView"; | ||
} | ||
|
||
void RichAnswersTranslationView::OnFocus() { | ||
View* wants_focus = focus_search_->FindNextFocusableView( | ||
/* starting_view= */ nullptr, | ||
views::FocusSearch::SearchDirection::kForwards, | ||
views::FocusSearch::TraversalDirection::kDown, | ||
views::FocusSearch::StartingViewPolicy::kCheckStartingView, | ||
views::FocusSearch::AnchoredDialogPolicy::kSkipAnchoredDialog, | ||
/* focus_traversable= */ nullptr, | ||
/* focus_traversable_view= */ nullptr); | ||
if (wants_focus != this) { | ||
wants_focus->RequestFocus(); | ||
} else { | ||
NotifyAccessibilityEvent(ax::mojom::Event::kFocus, true); | ||
} | ||
} | ||
|
||
views::FocusTraversable* RichAnswersTranslationView::GetPaneFocusTraversable() { | ||
return focus_search_.get(); | ||
} | ||
|
||
void RichAnswersTranslationView::InitLayout() { | ||
SetLayoutManager(std::make_unique<views::FillLayout>()); | ||
} | ||
|
||
std::vector<views::View*> RichAnswersTranslationView::GetFocusableViews() { | ||
std::vector<views::View*> focusable_views; | ||
focusable_views.push_back(this); | ||
|
||
return focusable_views; | ||
} |
52 changes: 52 additions & 0 deletions
52
chrome/browser/ui/quick_answers/ui/rich_answers_translation_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_QUICK_ANSWERS_UI_RICH_ANSWERS_TRANSLATION_VIEW_H_ | ||
#define CHROME_BROWSER_UI_QUICK_ANSWERS_UI_RICH_ANSWERS_TRANSLATION_VIEW_H_ | ||
|
||
#include <vector> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "chrome/browser/ui/quick_answers/ui/quick_answers_focus_search.h" | ||
#include "chrome/browser/ui/quick_answers/ui/rich_answers_view.h" | ||
#include "ui/events/event_handler.h" | ||
#include "ui/views/focus/focus_manager.h" | ||
#include "ui/views/view.h" | ||
|
||
namespace views { | ||
class ImageButton; | ||
} // namespace views | ||
|
||
// A bubble style view to show QuickAnswer. | ||
class RichAnswersTranslationView : public views::View { | ||
public: | ||
explicit RichAnswersTranslationView(const quick_answers::QuickAnswer& result); | ||
|
||
RichAnswersTranslationView(const RichAnswersTranslationView&) = delete; | ||
RichAnswersTranslationView& operator=(const RichAnswersTranslationView&) = | ||
delete; | ||
|
||
~RichAnswersTranslationView() override; | ||
|
||
// views::View: | ||
const char* GetClassName() const override; | ||
void OnFocus() override; | ||
views::FocusTraversable* GetPaneFocusTraversable() override; | ||
|
||
private: | ||
void InitLayout(); | ||
|
||
// QuickAnswersFocusSearch::GetFocusableViewsCallback to poll currently | ||
// focusable views. | ||
std::vector<views::View*> GetFocusableViews(); | ||
|
||
raw_ptr<views::View> base_view_ = nullptr; | ||
raw_ptr<views::ImageButton> settings_button_ = nullptr; | ||
|
||
std::unique_ptr<QuickAnswersFocusSearch> focus_search_; | ||
base::WeakPtrFactory<RichAnswersTranslationView> weak_factory_{this}; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_QUICK_ANSWERS_UI_QUICK_ANSWERS_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.