diff --git a/browser/ui/views/text_recognition_dialog_view.cc b/browser/ui/views/text_recognition_dialog_view.cc index 79a5b76e53e9..077590cbbb0a 100644 --- a/browser/ui/views/text_recognition_dialog_view.cc +++ b/browser/ui/views/text_recognition_dialog_view.cc @@ -127,8 +127,13 @@ TextRecognitionDialogView::TextRecognitionDialogView(const SkBitmap& image) header_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); header_label_->SetProperty(views::kMarginsKey, gfx::Insets::TLBR(0, 0, 10, 0)); +} + +TextRecognitionDialogView::~TextRecognitionDialogView() = default; +void TextRecognitionDialogView::AddedToWidget() { #if BUILDFLAG(IS_WIN) + // Start text extracting after getting language list to make code simpler. com_task_runner_ = base::ThreadPool::CreateCOMSTATaskRunner({base::MayBlock()}); com_task_runner_->PostTaskAndReplyWithResult( @@ -137,13 +142,11 @@ TextRecognitionDialogView::TextRecognitionDialogView(const SkBitmap& image) base::BindOnce( &TextRecognitionDialogView::OnGetAvailableRecognizerLanguages, weak_factory_.GetWeakPtr())); -#endif - +#else StartExtractingText(); +#endif } -TextRecognitionDialogView::~TextRecognitionDialogView() = default; - void TextRecognitionDialogView::StartExtractingText( const std::string& language_code) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); @@ -165,6 +168,7 @@ void TextRecognitionDialogView::StartExtractingText( header_label_->SetText(brave_l10n::GetLocalizedResourceUTF16String( IDS_TEXT_RECOGNITION_DIALOG_HEADER_IN_PROGRESS)); + AdjustWidgetSize(); #if BUILDFLAG(IS_MAC) base::ThreadPool::PostTaskAndReplyWithResult( @@ -250,6 +254,7 @@ void TextRecognitionDialogView::UpdateContents( } void TextRecognitionDialogView::AdjustWidgetSize() { + DCHECK(GetWidget()); GetWidget()->SetSize(GetDialogClientView()->GetPreferredSize()); } @@ -283,8 +288,12 @@ void TextRecognitionDialogView::OnGetAvailableRecognizerLanguages( base::BindRepeating(&TextRecognitionDialogView::OnLanguageOptionchanged, base::Unretained(this))); combobox_->SetProperty(views::kMarginsKey, gfx::Insets::TLBR(0, 0, 10, 0)); - combobox_->SetEnabled(result_ ? true : false); - AdjustWidgetSize(); + + // Enabled state is updated during the extracting. + // While extracting, it's disabled and then enabled when extracting is done. + combobox_->SetEnabled(false); + + StartExtractingText(); } bool TextRecognitionDialogView::OnLanguageOptionchanged(size_t index) { diff --git a/browser/ui/views/text_recognition_dialog_view.h b/browser/ui/views/text_recognition_dialog_view.h index 3f01ecca8df1..03daea8389b8 100644 --- a/browser/ui/views/text_recognition_dialog_view.h +++ b/browser/ui/views/text_recognition_dialog_view.h @@ -48,6 +48,9 @@ class TextRecognitionDialogView : public views::DialogDelegateView { private: FRIEND_TEST_ALL_PREFIXES(TextRecognitionBrowserTest, TextRecognitionTest); + // views::DialogDelegateView overrides: + void AddedToWidget() override; + void OnGetTextFromImage(const std::vector& text); #if BUILDFLAG(IS_WIN)