Commit 533c3feb authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Add OmniboxRowView to contain a header and OmniboxResultView

With the new suggestion headers that are coming, go/omniboxtransparency,
some rows are going to have need to paint headers above the
OmniboxResultView.

I considered adding the header to OmniboxResultView, but this didn't
make sense for reasons detailed in some in-code comments.

So I'm adding a new lightweight OmniboxRowView class to be a parent of
both the OmniboxResultView and the optional header View that sits right
above it.

The header View is not implemented yet.

Bug: 1052522
Change-Id: I693fa2dec0aa194da69f5fc744fe1099817f5ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130814
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756803}
parent de012ee8
......@@ -3140,6 +3140,8 @@ jumbo_static_library("ui") {
"views/omnibox/omnibox_popup_contents_view.h",
"views/omnibox/omnibox_result_view.cc",
"views/omnibox/omnibox_result_view.h",
"views/omnibox/omnibox_row_view.cc",
"views/omnibox/omnibox_row_view.h",
"views/omnibox/omnibox_tab_switch_button.cc",
"views/omnibox/omnibox_tab_switch_button.h",
"views/omnibox/omnibox_text_view.cc",
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_row_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
#include "chrome/browser/ui/views/omnibox/rounded_omnibox_results_frame.h"
#include "chrome/browser/ui/views/omnibox/webui_omnibox_popup_view.h"
......@@ -207,7 +208,7 @@ OmniboxResultView* OmniboxPopupContentsView::result_view_at(size_t i) {
if (i >= children().size())
return nullptr;
return static_cast<OmniboxResultView*>(children()[i]);
return static_cast<OmniboxRowView*>(children()[i])->result_view();
}
bool OmniboxPopupContentsView::InExplicitExperimentalKeywordMode() {
......@@ -303,19 +304,26 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
// be expensive to create due to loading font data, this saves time and
// memory during browser startup.
if (children().size() == i) {
AddChildView(std::make_unique<OmniboxResultView>(this, i));
AddChildView(std::make_unique<OmniboxRowView>(
std::make_unique<OmniboxResultView>(this, i)));
}
OmniboxResultView* view = result_view_at(i);
OmniboxRowView* const row_view =
static_cast<OmniboxRowView*>(children()[i]);
row_view->SetVisible(true);
OmniboxResultView* const result_view = row_view->result_view();
const AutocompleteMatch& match = GetMatchAtIndex(i);
view->SetMatch(match);
view->SetVisible(true);
result_view->SetMatch(match);
const SkBitmap* bitmap = model_->RichSuggestionBitmapAt(i);
if (bitmap)
view->SetRichSuggestionImage(
if (bitmap) {
result_view->SetRichSuggestionImage(
gfx::ImageSkia::CreateFrom1xBitmap(*bitmap));
}
}
// If we have more views than matches, hide the surplus ones.
for (auto i = children().begin() + result_size; i != children().end(); ++i)
(*i)->SetVisible(false);
}
......
// Copyright 2020 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 "chrome/browser/ui/views/omnibox/omnibox_row_view.h"
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "ui/views/layout/box_layout.h"
OmniboxRowView::OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view) {
DCHECK(result_view);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
result_view_ = AddChildView(std::move(result_view));
}
void OmniboxRowView::SetHeader(base::Optional<int> suggestion_group_id,
const base::string16& header_text) {
// TODO(tommycli): Create a child header view here. Not implemented yet.
}
// Copyright 2020 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 CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
#include "base/optional.h"
#include "base/strings/string16.h"
#include "ui/views/view.h"
class OmniboxResultView;
// The View that's a direct child of the OmniboxPopupContentsView, one per row.
// This, in turn, has a child OmniboxResultView and an optional header that is
// painted right above it. The header is not a child of OmniboxResultView
// because it's logically not part of the result view:
// - Hovering the header doesn't highlight the result view.
// - Clicking the header doesn't navigate to the match.
// - It's the header for multiple matches, it's just painted above this row.
class OmniboxRowView : public views::View {
public:
explicit OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view);
// Sets the header that appears above this row. |suggestion_group_id| can be
// base::nullopt, and that will hide the header.
void SetHeader(base::Optional<int> suggestion_group_id,
const base::string16& header_text);
// The result view associated with this row.
OmniboxResultView* result_view() const { return result_view_; }
private:
// Non-owning pointer to the result view for this row. This is never nullptr.
OmniboxResultView* result_view_;
};
#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
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