Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3837)

Unified Diff: chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc

Issue 2817663003: Rendering text on insecure-site warnings for WebVR (Closed)
Patch Set: Measuring text to accomplish a more proper layout and positioning icons according to RTL languages Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc
diff --git a/chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc b/chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc
index f215587252df04122e570355383087ba38bf306c..827e6fb707ffd09c942deca8e49e23da37917381 100644
--- a/chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc
+++ b/chrome/browser/android/vr_shell/textures/insecure_content_transient_texture.cc
@@ -8,6 +8,7 @@
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/paint_vector_icon.h"
@@ -20,6 +21,10 @@ namespace {
const SkColor kBackgroundColor = 0xCC1A1A1A;
const SkColor kForegroundColor = SK_ColorWHITE;
+constexpr float kBorderFactor = 0.045;
+constexpr float kIconSizeFactor = 0.25;
+constexpr float kFontSizeFactor = 0.045;
+constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor;
} // namespace
@@ -27,9 +32,6 @@ InsecureContentTransientTexture::InsecureContentTransientTexture(
int texture_handle,
int texture_size)
: UITexture(texture_handle, texture_size) {
- // Ensuring height is half the width.
- DCHECK(texture_size_ % 2 == 0);
- height_ = texture_size_ / 2;
}
InsecureContentTransientTexture::~InsecureContentTransientTexture() = default;
@@ -37,16 +39,43 @@ InsecureContentTransientTexture::~InsecureContentTransientTexture() = default;
void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas) {
cc::PaintFlags flags;
flags.setColor(kBackgroundColor);
- canvas->DrawRoundRect(gfx::Rect(texture_size_, height_), height_ * 0.1,
- flags);
+
+ int text_flags = gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::MULTI_LINE;
+ auto text =
+ l10n_util::GetStringUTF16(IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT);
+ auto fonts = GetFontList(texture_size_ * kFontSizeFactor, text);
+
+ int text_width = texture_size_ * kTextWidthFactor;
+ int text_height = 0; // Will be increased during text measurement.
+ canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags);
mthiesse 2017/04/21 00:12:24 Canvas::SizeStringInt is a static function
+ // Making sure that the icon fits in the box.
+ text_height = std::max(
+ text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor)));
+ // Making sure the drawing fits within the texture.
+ text_height = std::min(
+ text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * texture_size_));
+ height_ =
+ static_cast<int>(ceil(texture_size_ * 2 * kBorderFactor + text_height));
+
+ canvas->DrawRoundRect(gfx::Rect(texture_size_, height_),
+ height_ * kBorderFactor, flags);
+
canvas->Save();
- canvas->Translate({height_ * 0.1, height_ * 0.25});
- PaintVectorIcon(canvas, ui::kInfoOutlineIcon, height_ * 0.5,
+ canvas->Translate({IsRTL() ? 2 * kBorderFactor * texture_size_ + text_width
+ : texture_size_ * kBorderFactor,
+ (height_ - kIconSizeFactor * texture_size_) / 2.0});
+ PaintVectorIcon(canvas, ui::kInfoOutlineIcon, texture_size_ * kIconSizeFactor,
kForegroundColor);
canvas->Restore();
+
canvas->Save();
- canvas->Translate({height_ * 0.7, height_ * 0.1});
- // TODO(acondor): Draw text IDS_PAGE_INFO_INSECURE_WEBVR_CONTENT_TRANSIENT.
+ canvas->Translate(
+ {IsRTL() ? kBorderFactor * texture_size_
+ : texture_size_ * (2 * kBorderFactor + kIconSizeFactor),
+ texture_size_ * kBorderFactor});
+ canvas->DrawStringRectWithFlags(
+ text, fonts, kForegroundColor,
+ gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags);
canvas->Restore();
}

Powered by Google App Engine
This is Rietveld 408576698