Commit 045cdc93 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Add a separator for the Touchable omnibox frame.

Move all layout to Layout() so that it updates correctly when the
browser window is resized with the results dropdown open.

Bug: 801583
Change-Id: I7b931ff3d3b8623e5a01b4543b441767845818ac
Reviewed-on: https://chromium-review.googlesource.com/942562
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542051}
parent c7fcdeaa
......@@ -52,6 +52,9 @@ ui::NativeTheme::ColorId GetLegacyColorId(OmniboxPart part,
state, NativeId::kColorId_ResultsTableNormalBackground,
NativeId::kColorId_ResultsTableHoveredBackground,
NativeId::kColorId_ResultsTableSelectedBackground);
case OmniboxPart::RESULTS_SEPARATOR:
NOTREACHED();
break;
}
return kInvalidColorId;
}
......@@ -97,6 +100,10 @@ SkColor GetOmniboxColor(OmniboxPart part,
return color_utils::BlendTowardOppositeLuma(
dark ? gfx::kGoogleGrey800 : SK_ColorWHITE,
NormalHoveredSelectedOrBoth<SkAlpha>(state, 0x00, 0x0f, 0x14, 0x24));
case OmniboxPart::RESULTS_SEPARATOR:
// The dark base color doesn't appear in the MD2 spec, just Chrome's.
return dark ? SkColorSetARGB(0x6e, 0x16, 0x17, 0x1a) // 43% alpha.
: SkColorSetA(gfx::kGoogleGrey900, 0x24); // 14% alpha.
}
return gfx::kPlaceholderColor;
}
......@@ -10,6 +10,7 @@
// A part of the omnibox (location bar, location bar decoration, or dropdown).
enum class OmniboxPart {
RESULTS_BACKGROUND, // Background of the results dropdown.
RESULTS_SEPARATOR, // Separator between the input row and the results rows.
};
// The tint of the omnibox theme. E.g. Incognito may use a DARK tint. NATIVE is
......
......@@ -382,6 +382,15 @@ gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
return origin;
}
int LocationBarView::GetTextInsetForNormalInputStart() const {
// Note that this does not need to account for the internal Textfield border,
// since that's subtracted during layout.
return GetHorizontalEdgeThickness() +
GetLayoutConstant(LOCATION_BAR_ICON_SIZE) +
2 * GetLayoutConstant(LOCATION_BAR_ICON_INTERIOR_PADDING) +
GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING);
}
void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
ime_inline_autocomplete_view_->SetText(text);
ime_inline_autocomplete_view_->SetVisible(!text.empty());
......
......@@ -173,6 +173,10 @@ class LocationBarView : public LocationBar,
// not where the icons are shown).
gfx::Point GetOmniboxViewOrigin() const;
// Returns the inset from the edge of the location bar where text begins when
// only a location icon is showing (no security chip or keyword bubble).
int GetTextInsetForNormalInputStart() const;
// Shows |text| as an inline autocompletion. This is useful for IMEs, where
// we can't show the autocompletion inside the actual OmniboxView. See
// comments on |ime_inline_autocomplete_view_|.
......
......@@ -7,6 +7,7 @@
#include "build/build_config.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/compositor/layer.h"
......@@ -24,12 +25,41 @@ namespace {
// Value from the spec controlling appearance of the shadow.
constexpr int kElevation = 16;
// The layout height (in DIPs) of the view drawing the separator above results.
// The top of this view aligns with the bottom edge of the location bar.
constexpr int kSeparatorViewHeightDIP = 1;
// View at the top of the frame which paints transparent pixels to make a hole
// so that the location bar shows through.
class TopBackgroundView : public views::View {
public:
explicit TopBackgroundView(SkColor color) {
auto background =
std::make_unique<BackgroundWith1PxBorder>(SK_ColorTRANSPARENT, color);
background->set_blend_mode(SkBlendMode::kSrc);
SetBackground(std::move(background));
}
};
class SeparatorView : public views::View {
public:
explicit SeparatorView(SkColor color) : color_(color) {}
// Views:View:
void OnPaint(gfx::Canvas* canvas) override {
BrowserView::Paint1pxHorizontalLine(canvas, color_, GetLocalBounds(), true);
}
private:
const SkColor color_;
};
// Insets used to position |contents_| within |contents_host_|.
gfx::Insets GetContentInsets(views::View* location_bar) {
return gfx::Insets(
RoundedOmniboxResultsFrame::kLocationBarAlignmentInsets.top(), 0,
0, 0) +
gfx::Insets(location_bar->height(), 0, 0, 0);
gfx::Insets(location_bar->height() + kSeparatorViewHeightDIP, 0, 0, 0);
}
#if defined(USE_AURA)
......@@ -51,7 +81,10 @@ constexpr gfx::Insets RoundedOmniboxResultsFrame::kLocationBarAlignmentInsets;
RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame(
views::View* contents,
LocationBarView* location_bar)
: content_insets_(GetContentInsets(location_bar)), contents_(contents) {
: content_insets_(GetContentInsets(location_bar)),
location_bar_height_(location_bar->height()),
separator_inset_(location_bar->GetTextInsetForNormalInputStart()),
contents_(contents) {
// Host the contents in its own View to simplify layout and clipping.
contents_host_ = new views::View();
contents_host_->SetPaintToLayer();
......@@ -73,19 +106,13 @@ RoundedOmniboxResultsFrame::RoundedOmniboxResultsFrame(
contents_mask_->layer()->SetFillsBoundsOpaquely(false);
contents_host_->layer()->SetMaskLayer(contents_mask_->layer());
// Paint the omnibox border with transparent pixels to make a hole.
views::View* top_background = new views::View();
auto background = std::make_unique<BackgroundWith1PxBorder>(
SK_ColorTRANSPARENT, background_color);
background->set_blend_mode(SkBlendMode::kSrc);
top_background->SetBackground(std::move(background));
gfx::Size location_bar_size = location_bar->bounds().size();
top_background->SetBounds(
kLocationBarAlignmentInsets.left(), kLocationBarAlignmentInsets.top(),
location_bar_size.width(), location_bar_size.height());
contents_host_->AddChildView(top_background);
top_background_ = new TopBackgroundView(background_color);
separator_ = new SeparatorView(
GetOmniboxColor(OmniboxPart::RESULTS_SEPARATOR, location_bar->tint()));
contents_host_->AddChildView(top_background_);
contents_host_->AddChildView(separator_);
contents_host_->AddChildView(contents_);
AddChildView(contents_host_);
}
......@@ -118,9 +145,20 @@ void RoundedOmniboxResultsFrame::Layout() {
// the Widget is fast on ChromeOS, but slow on other platforms, and can't be
// animated smoothly.
// TODO(tapted): Investigate using a static Widget size.
gfx::Rect bounds = GetLocalBounds();
const gfx::Rect bounds = GetLocalBounds();
contents_host_->SetBoundsRect(bounds);
contents_mask_->layer()->SetBounds(gfx::Rect(bounds.size()));
contents_mask_->layer()->SetBounds(bounds);
// Manual layout.
gfx::Rect top_bounds = bounds;
top_bounds.Inset(kLocationBarAlignmentInsets);
top_bounds.set_height(location_bar_height_);
top_background_->SetBoundsRect(top_bounds);
top_bounds.set_y(top_bounds.bottom()); // Shift down.
top_bounds.Inset(separator_inset_, 0); // Inset the width further.
top_bounds.set_height(kSeparatorViewHeightDIP);
separator_->SetBoundsRect(top_bounds);
gfx::Rect results_bounds = gfx::Rect(bounds.size());
results_bounds.Inset(content_insets_);
......
......@@ -37,10 +37,15 @@ class RoundedOmniboxResultsFrame : public views::View {
void AddedToWidget() override;
private:
// Fixed layout constants.
const gfx::Insets content_insets_;
const int location_bar_height_;
const int separator_inset_;
std::unique_ptr<ui::LayerOwner> contents_mask_;
views::View* top_background_ = nullptr;
views::View* separator_ = nullptr;
views::View* contents_ = nullptr;
views::View* contents_host_ = nullptr;
......
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