Commit b8e0f4d1 authored by evliu's avatar evliu Committed by Commit Bot

Update the caption bubble to support non-ASCII characters

This CL updates |CaptionBubble::OnTextChanged| to support non-ASCII
characters.

Bug: 1111919
Change-Id: I1733160390f4e3fd6cae5da6d02edbcee0258fd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332305Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarAbigail Klein <abigailbklein@google.com>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#795376}
parent 7c1b9cbd
...@@ -525,7 +525,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) { ...@@ -525,7 +525,7 @@ void CaptionBubble::SetModel(CaptionBubbleModel* model) {
void CaptionBubble::OnTextChanged() { void CaptionBubble::OnTextChanged() {
DCHECK(model_); DCHECK(model_);
label_->SetText(base::ASCIIToUTF16(model_->GetFullText())); label_->SetText(base::UTF8ToUTF16(model_->GetFullText()));
UpdateBubbleAndWaitTextVisibility(); UpdateBubbleAndWaitTextVisibility();
} }
......
...@@ -62,6 +62,8 @@ class CaptionBubble : public views::BubbleDialogDelegateView, ...@@ -62,6 +62,8 @@ class CaptionBubble : public views::BubbleDialogDelegateView,
// For the provided line index, gets the corresponding rendered line in the // For the provided line index, gets the corresponding rendered line in the
// label and returns the text position of the first character of that line. // label and returns the text position of the first character of that line.
// Returns the same value regardless of whether the label is visible or not. // Returns the same value regardless of whether the label is visible or not.
// TODO(crbug.com/1055150): This feature is launching for English first.
// Make sure this is correct for all languages.
size_t GetTextIndexOfLineInLabel(size_t line) const; size_t GetTextIndexOfLineInLabel(size_t line) const;
// Returns the number of lines in the caption bubble label that are rendered. // Returns the number of lines in the caption bubble label that are rendered.
......
...@@ -878,4 +878,12 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) { ...@@ -878,4 +878,12 @@ IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, ExpandsAndCollapses) {
EXPECT_EQ(line_height, GetLabel()->GetBoundsInScreen().height()); EXPECT_EQ(line_height, GetLabel()->GetBoundsInScreen().height());
} }
IN_PROC_BROWSER_TEST_F(CaptionBubbleControllerViewsTest, NonAsciiCharacter) {
OnPartialTranscription("犬は最高です");
EXPECT_EQ("犬は最高です", GetLabelText());
OnFinalTranscription("猫も大丈夫");
EXPECT_EQ("猫も大丈夫", GetLabelText());
}
} // namespace captions } // namespace captions
...@@ -112,7 +112,6 @@ void CaptionBubbleModel::CommitPartialText() { ...@@ -112,7 +112,6 @@ void CaptionBubbleModel::CommitPartialText() {
// observer that the text has changed. // observer that the text has changed.
const size_t num_lines = observer_->GetNumLinesInLabel(); const size_t num_lines = observer_->GetNumLinesInLabel();
if (num_lines > kMaxLines) { if (num_lines > kMaxLines) {
DCHECK(base::IsStringASCII(final_text_));
const size_t truncate_index = const size_t truncate_index =
observer_->GetTextIndexOfLineInLabel(num_lines - kMaxLines); observer_->GetTextIndexOfLineInLabel(num_lines - kMaxLines);
final_text_.erase(0, truncate_index); final_text_.erase(0, truncate_index);
......
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