Commit cdf2537f authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Forces URL directionality for custom tab bar location.

This is a security UX improvement for RTL domains. Before this change
http://مثال.com/ would be displayed as com.مثال instead of مثال.com

Bug: 943362, 943366
Change-Id: I967216bb402b12dc437e05274ff8ea63e1544f06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529975
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642348}
parent ddffebdb
......@@ -25,6 +25,7 @@
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/text_constants.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/image_button.h"
......@@ -86,7 +87,8 @@ class CustomTabBarTitleOriginView : public views::View {
title_label_ = new views::Label(base::string16(), CONTEXT_BODY_TEXT_LARGE,
views::style::TextStyle::STYLE_PRIMARY);
location_label_ = new views::Label(
base::string16(), CONTEXT_BODY_TEXT_SMALL, STYLE_SECONDARY);
base::string16(), CONTEXT_BODY_TEXT_SMALL, STYLE_SECONDARY,
gfx::DirectionalityMode::DIRECTIONALITY_AS_URL);
title_label_->SetBackgroundColor(background_color);
title_label_->SetElideBehavior(gfx::ElideBehavior::ELIDE_TAIL);
......
......@@ -52,9 +52,12 @@ Label::Label() : Label(base::string16()) {
Label::Label(const base::string16& text)
: Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {}
Label::Label(const base::string16& text, int text_context, int text_style)
Label::Label(const base::string16& text,
int text_context,
int text_style,
gfx::DirectionalityMode directionality_mode)
: text_context_(text_context), context_menu_contents_(this) {
Init(text, style::GetFont(text_context, text_style));
Init(text, style::GetFont(text_context, text_style), directionality_mode);
SetLineHeight(style::GetLineHeight(text_context, text_style));
// If an explicit style is given, ignore color changes due to the NativeTheme.
......@@ -64,7 +67,7 @@ Label::Label(const base::string16& text, int text_context, int text_style)
Label::Label(const base::string16& text, const CustomFont& font)
: text_context_(style::CONTEXT_LABEL), context_menu_contents_(this) {
Init(text, font.font_list);
Init(text, font.font_list, gfx::DirectionalityMode::DIRECTIONALITY_FROM_TEXT);
}
Label::~Label() = default;
......@@ -784,11 +787,13 @@ const gfx::RenderText* Label::GetRenderTextForSelectionController() const {
return display_text_.get();
}
void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
void Label::Init(const base::string16& text,
const gfx::FontList& font_list,
gfx::DirectionalityMode directionality_mode) {
full_text_ = gfx::RenderText::CreateHarfBuzzInstance();
DCHECK(full_text_->MultilineSupported());
full_text_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
full_text_->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT);
full_text_->SetDirectionalityMode(directionality_mode);
// NOTE: |full_text_| should not be elided at all. This is used to keep
// some properties and to compute the size of the string.
full_text_->SetElideBehavior(gfx::NO_ELIDE);
......
......@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/render_text.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/selection_controller_delegate.h"
#include "ui/views/style/typography.h"
......@@ -54,9 +55,13 @@ class VIEWS_EXPORT Label : public View,
// Construct a Label in the given |text_context|. The |text_style| can change
// later, so provide a default. The |text_context| is fixed.
// By default text directionality will be derived from the label text, however
// it can be overriden with |directionality_mode|.
Label(const base::string16& text,
int text_context,
int text_style = style::STYLE_PRIMARY);
int text_style = style::STYLE_PRIMARY,
gfx::DirectionalityMode directionality_mode =
gfx::DirectionalityMode::DIRECTIONALITY_FROM_TEXT);
// Construct a Label with the given |font| description.
Label(const base::string16& text, const CustomFont& font);
......@@ -301,7 +306,9 @@ class VIEWS_EXPORT Label : public View,
const gfx::RenderText* GetRenderTextForSelectionController() const;
void Init(const base::string16& text, const gfx::FontList& font_list);
void Init(const base::string16& text,
const gfx::FontList& font_list,
gfx::DirectionalityMode directionality_mode);
void ResetLayout();
......
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