Chromium Code Reviews| 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 827e6fb707ffd09c942deca8e49e23da37917381..31912d04b09c39557a7f220c5de2f875a1c755b5 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 |
| @@ -28,59 +28,62 @@ constexpr float kTextWidthFactor = 1.0 - 3 * kBorderFactor - kIconSizeFactor; |
| } // namespace |
| -InsecureContentTransientTexture::InsecureContentTransientTexture( |
| - int texture_handle, |
| - int texture_size) |
| - : UITexture(texture_handle, texture_size) { |
| -} |
| +InsecureContentTransientTexture::InsecureContentTransientTexture() = default; |
| InsecureContentTransientTexture::~InsecureContentTransientTexture() = default; |
| -void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas) { |
| +void InsecureContentTransientTexture::Draw(gfx::Canvas* canvas, |
| + const gfx::Size& texture_size) { |
| + size_.set_width(texture_size.width()); |
| + int max_height = texture_size.height(); |
| cc::PaintFlags flags; |
| flags.setColor(kBackgroundColor); |
| 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; |
| + auto fonts = GetFontList(size_.width() * kFontSizeFactor, text); |
| + int text_width = size_.width() * kTextWidthFactor; |
| int text_height = 0; // Will be increased during text measurement. |
| canvas->SizeStringInt(text, fonts, &text_width, &text_height, 0, text_flags); |
| // Making sure that the icon fits in the box. |
| text_height = std::max( |
| - text_height, static_cast<int>(ceil(texture_size_ * kIconSizeFactor))); |
| + text_height, static_cast<int>(ceil(size_.width() * 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); |
| + text_height, static_cast<int>((1.0 - 2 * kBorderFactor) * size_.width())); |
| + size_.set_height(size_.width() * 2 * kBorderFactor + text_height); |
| + DCHECK(size_.height() <= max_height); |
|
cjgrant
2017/04/21 14:30:13
DCHECK_LE()
mthiesse
2017/04/21 15:05:12
Done.
|
| + canvas->DrawRoundRect(gfx::Rect(size_.width(), size_.height()), |
| + size_.height() * kBorderFactor, flags); |
| canvas->Save(); |
| - 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, |
| + canvas->Translate( |
| + gfx::Vector2d(IsRTL() ? 2 * kBorderFactor * size_.width() + text_width |
| + : size_.width() * kBorderFactor, |
| + (size_.height() - kIconSizeFactor * size_.width()) / 2.0)); |
| + PaintVectorIcon(canvas, ui::kInfoOutlineIcon, size_.width() * kIconSizeFactor, |
| kForegroundColor); |
| canvas->Restore(); |
| canvas->Save(); |
| - canvas->Translate( |
| - {IsRTL() ? kBorderFactor * texture_size_ |
| - : texture_size_ * (2 * kBorderFactor + kIconSizeFactor), |
| - texture_size_ * kBorderFactor}); |
| + canvas->Translate(gfx::Vector2d( |
| + IsRTL() ? kBorderFactor * size_.width() |
| + : size_.width() * (2 * kBorderFactor + kIconSizeFactor), |
| + size_.width() * kBorderFactor)); |
| canvas->DrawStringRectWithFlags( |
| text, fonts, kForegroundColor, |
| - gfx::Rect(kTextWidthFactor * texture_size_, text_height), text_flags); |
| + gfx::Rect(kTextWidthFactor * size_.width(), text_height), text_flags); |
| canvas->Restore(); |
| } |
| -void InsecureContentTransientTexture::SetSize() { |
| - size_.SetSize(texture_size_, height_); |
| +gfx::Size InsecureContentTransientTexture::GetPreferredTextureSize( |
| + int width) const { |
| + return gfx::Size(width, width); |
| +} |
| + |
| +gfx::SizeF InsecureContentTransientTexture::GetActualSize() const { |
| + return size_; |
| } |
| } // namespace vr_shell |