| Index: chrome/browser/android/vr_shell/textures/url_bar_texture.cc
|
| diff --git a/chrome/browser/android/vr_shell/textures/url_bar_texture.cc b/chrome/browser/android/vr_shell/textures/url_bar_texture.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d1861dd15b2d033e4ab0b2d60d78307b5f60f5c2
|
| --- /dev/null
|
| +++ b/chrome/browser/android/vr_shell/textures/url_bar_texture.cc
|
| @@ -0,0 +1,135 @@
|
| +// Copyright 2017 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/android/vr_shell/textures/url_bar_texture.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "cc/paint/skia_paint_canvas.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/font.h"
|
| +#include "ui/gfx/font_list.h"
|
| +#include "ui/gfx/geometry/rect.h"
|
| +#include "ui/gfx/paint_vector_icon.h"
|
| +#include "ui/gfx/vector_icon_types.h"
|
| +#include "ui/vector_icons/vector_icons.h"
|
| +
|
| +namespace vr_shell {
|
| +
|
| +namespace {
|
| +
|
| +static constexpr SkColor kTextureBackground = 0x00AAAAAA;
|
| +static constexpr SkColor kBackground = 0xCCAAAAAA;
|
| +static constexpr SkColor kBackgroundHover = 0xCCDDDDDD;
|
| +static constexpr SkColor kForeground = 0xCC444444;
|
| +static constexpr SkColor kSeparatorColor =
|
| + SkColorSetARGBMacro(256 * 0.2, 0, 0, 0);
|
| +
|
| +static constexpr float kWidth = 0.672;
|
| +static constexpr float kHeight = 0.088;
|
| +static constexpr float kFontHeight = 0.027;
|
| +static constexpr float kBackButtonWidth = kHeight;
|
| +static constexpr float kBackIconHeight = 0.05;
|
| +static constexpr float kBackIconOffset = 0.005;
|
| +static constexpr float kSecurityFieldWidth = 0.06;
|
| +static constexpr float kSecurityIconHeight = 0.03;
|
| +static constexpr float kUrlRightMargin = 0.02;
|
| +static constexpr float kSeparatorWidth = 0.002;
|
| +
|
| +} // namespace
|
| +
|
| +UrlBarTexture::UrlBarTexture() = default;
|
| +
|
| +UrlBarTexture::~UrlBarTexture() = default;
|
| +
|
| +void UrlBarTexture::SetHover(bool hover) {
|
| + hover_ = hover;
|
| +}
|
| +
|
| +void UrlBarTexture::SetURL(const GURL& gurl) {
|
| + gurl_ = gurl;
|
| +}
|
| +
|
| +float UrlBarTexture::ToPixels(float meters) const {
|
| + return meters * size_.width() / kWidth;
|
| +}
|
| +
|
| +void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
|
| + size_.set_height(texture_size.height());
|
| + size_.set_width(texture_size.width());
|
| +
|
| + canvas->save();
|
| + canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
|
| +
|
| + // Make a gfx canvas to support utility drawing methods.
|
| + cc::SkiaPaintCanvas paint_canvas(canvas);
|
| + gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
|
| +
|
| + canvas->drawColor(kTextureBackground);
|
| +
|
| + // Back button area.
|
| + SkRRect round_rect;
|
| + SkVector rounded_corner = {kHeight / 2, kHeight / 2};
|
| + SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
|
| + round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
|
| + SkPaint paint;
|
| + paint.setColor(hover_ ? kBackgroundHover : kBackground);
|
| + canvas->drawRRect(round_rect, paint);
|
| +
|
| + // URL area.
|
| + paint.setColor(kBackground);
|
| + SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
|
| + round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
|
| + canvas->drawRRect(round_rect, paint);
|
| +
|
| + // Back button / URL separator vertical line.
|
| + paint.setColor(kSeparatorColor);
|
| + canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight),
|
| + paint);
|
| +
|
| + // Back button icon.
|
| + canvas->save();
|
| + canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
|
| + canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
|
| + int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
|
| + float icon_scale = kBackIconHeight / icon_default_height;
|
| + canvas->scale(icon_scale, icon_scale);
|
| + PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground);
|
| + canvas->restore();
|
| +
|
| + // Site security state icon.
|
| + // TODO(cjgrant): Plug in the correct icons based on security level.
|
| + canvas->save();
|
| + canvas->translate(
|
| + kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
|
| + kHeight / 2);
|
| + canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
|
| + icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
|
| + icon_scale = kSecurityIconHeight / icon_default_height;
|
| + canvas->scale(icon_scale, icon_scale);
|
| + PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground);
|
| + canvas->restore();
|
| +
|
| + canvas->restore();
|
| +
|
| + // Draw text based on pixel sizes rather than meters, for correct font sizing.
|
| + int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
|
| + int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT;
|
| + float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth;
|
| + float url_width = kWidth - url_x - kUrlRightMargin;
|
| + gfx_canvas.DrawStringRectWithFlags(
|
| + base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height),
|
| + SK_ColorBLACK,
|
| + gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)),
|
| + text_flags);
|
| +}
|
| +
|
| +gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
|
| + return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
|
| +}
|
| +
|
| +gfx::SizeF UrlBarTexture::GetDrawnSize() const {
|
| + return size_;
|
| +}
|
| +
|
| +} // namespace vr_shell
|
|
|