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

Side by Side Diff: chrome/browser/renderer_context_menu/spelling_menu_observer.cc

Issue 2244083002: Componentize spellcheck [4]: spellcheck/browser and android java-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" 5 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 15 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
16 #include "chrome/browser/renderer_context_menu/spelling_bubble_model.h" 16 #include "chrome/browser/renderer_context_menu/spelling_bubble_model.h"
17 #include "chrome/browser/spellchecker/feedback_sender.h"
18 #include "chrome/browser/spellchecker/spellcheck_factory.h" 17 #include "chrome/browser/spellchecker/spellcheck_factory.h"
19 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
20 #include "chrome/browser/spellchecker/spellcheck_platform.h"
21 #include "chrome/browser/spellchecker/spellcheck_service.h" 18 #include "chrome/browser/spellchecker/spellcheck_service.h"
22 #include "chrome/browser/spellchecker/spelling_service_client.h"
23 #include "chrome/browser/ui/confirm_bubble.h" 19 #include "chrome/browser/ui/confirm_bubble.h"
24 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
26 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
27 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
24 #include "components/spellcheck/browser/feedback_sender.h"
25 #include "components/spellcheck/browser/pref_names.h"
26 #include "components/spellcheck/browser/spellcheck_host_metrics.h"
27 #include "components/spellcheck/browser/spellcheck_platform.h"
28 #include "components/spellcheck/browser/spelling_service_client.h"
28 #include "components/spellcheck/common/spellcheck_common.h" 29 #include "components/spellcheck/common/spellcheck_common.h"
29 #include "components/spellcheck/common/spellcheck_result.h" 30 #include "components/spellcheck/common/spellcheck_result.h"
30 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/render_widget_host.h" 32 #include "content/public/browser/render_widget_host.h"
32 #include "content/public/browser/render_widget_host_view.h" 33 #include "content/public/browser/render_widget_host_view.h"
33 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
34 #include "content/public/common/context_menu_params.h" 35 #include "content/public/common/context_menu_params.h"
35 #include "extensions/browser/view_type_utils.h" 36 #include "extensions/browser/view_type_utils.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/gfx/geometry/rect.h" 38 #include "ui/gfx/geometry/rect.h"
38 39
39 using content::BrowserThread; 40 using content::BrowserThread;
40 41
41 const int kMaxSpellingSuggestions = 3; 42 const int kMaxSpellingSuggestions = 3;
42 43
43 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) 44 SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy)
44 : proxy_(proxy), 45 : proxy_(proxy),
45 loading_frame_(0), 46 loading_frame_(0),
46 succeeded_(false), 47 succeeded_(false),
47 misspelling_hash_(0), 48 misspelling_hash_(0),
48 client_(new SpellingServiceClient) { 49 client_(new SpellingServiceClient) {
49 if (proxy_ && proxy_->GetBrowserContext()) { 50 if (proxy_ && proxy_->GetBrowserContext()) {
50 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); 51 Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext());
51 integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService, 52 integrate_spelling_service_.Init(
52 profile->GetPrefs()); 53 spellcheck::prefs::kSpellCheckUseSpellingService, profile->GetPrefs());
53 } 54 }
54 } 55 }
55 56
56 SpellingMenuObserver::~SpellingMenuObserver() { 57 SpellingMenuObserver::~SpellingMenuObserver() {
57 } 58 }
58 59
59 void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { 60 void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
61 DCHECK(!params.misspelled_word.empty() || 62 DCHECK(!params.misspelled_word.empty() ||
62 params.dictionary_suggestions.empty()); 63 params.dictionary_suggestions.empty());
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); 288 content::RenderViewHost* rvh = proxy_->GetRenderViewHost();
288 gfx::Rect rect = rvh->GetWidget()->GetView()->GetViewBounds(); 289 gfx::Rect rect = rvh->GetWidget()->GetView()->GetViewBounds();
289 std::unique_ptr<SpellingBubbleModel> model( 290 std::unique_ptr<SpellingBubbleModel> model(
290 new SpellingBubbleModel(profile, proxy_->GetWebContents())); 291 new SpellingBubbleModel(profile, proxy_->GetWebContents()));
291 chrome::ShowConfirmBubble( 292 chrome::ShowConfirmBubble(
292 proxy_->GetWebContents()->GetTopLevelNativeWindow(), 293 proxy_->GetWebContents()->GetTopLevelNativeWindow(),
293 rvh->GetWidget()->GetView()->GetNativeView(), 294 rvh->GetWidget()->GetView()->GetNativeView(),
294 gfx::Point(rect.CenterPoint().x(), rect.y()), std::move(model)); 295 gfx::Point(rect.CenterPoint().x(), rect.y()), std::move(model));
295 } else { 296 } else {
296 if (profile) { 297 if (profile) {
297 profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, 298 profile->GetPrefs()->SetBoolean(
298 false); 299 spellcheck::prefs::kSpellCheckUseSpellingService, false);
299 } 300 }
300 } 301 }
301 } 302 }
302 } 303 }
303 304
304 void SpellingMenuObserver::OnMenuCancel() { 305 void SpellingMenuObserver::OnMenuCancel() {
305 content::BrowserContext* browser_context = proxy_->GetBrowserContext(); 306 content::BrowserContext* browser_context = proxy_->GetBrowserContext();
306 if (!browser_context) 307 if (!browser_context)
307 return; 308 return;
308 SpellcheckService* spellcheck = 309 SpellcheckService* spellcheck =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // Append '.' characters to the end of "Checking". 359 // Append '.' characters to the end of "Checking".
359 loading_frame_ = (loading_frame_ + 1) & 3; 360 loading_frame_ = (loading_frame_ + 1) & 3;
360 base::string16 loading_message = 361 base::string16 loading_message =
361 loading_message_ + base::string16(loading_frame_,'.'); 362 loading_message_ + base::string16(loading_frame_,'.');
362 363
363 // Update the menu item with the text. We disable this item to prevent users 364 // Update the menu item with the text. We disable this item to prevent users
364 // from selecting it. 365 // from selecting it.
365 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, 366 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false,
366 loading_message); 367 loading_message);
367 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698