| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ | 5 #ifndef CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ |
| 6 #define CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ | 6 #define CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <stack> | 10 #include <stack> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 virtual void PageTranslated(int page_id, | 41 virtual void PageTranslated(int page_id, |
| 42 const std::string& original_lang, | 42 const std::string& original_lang, |
| 43 const std::string& target_lang) = 0; | 43 const std::string& target_lang) = 0; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // The caller remains the owner of |text_translator|. | 46 // The caller remains the owner of |text_translator|. |
| 47 PageTranslator(TextTranslator* text_translator, | 47 PageTranslator(TextTranslator* text_translator, |
| 48 PageTranslatorDelegate* delegate); | 48 PageTranslatorDelegate* delegate); |
| 49 virtual ~PageTranslator(); | 49 virtual ~PageTranslator(); |
| 50 | 50 |
| 51 // Starts the translation process of |web_frame| from |source_lang| to | 51 // Translate the text in the page contained in |main_frame|. |
| 52 // |target_lang| where the languages are the ISO codes (ex: en, fr...). | 52 // It is translated from |source_lang| to |target_lang| where the languages |
| 53 void Translate(int page_id, | 53 // are the ISO codes (ex: en, fr...). |
| 54 WebKit::WebFrame* web_frame, | 54 // All sub-frames contained in |main_frame| are translated. |
| 55 std::string source_lang, | 55 void TranslatePage(int page_id, |
| 56 std::string target_lang); | 56 WebKit::WebFrame* main_frame, |
| 57 std::string source_lang, |
| 58 std::string target_lang); |
| 57 | 59 |
| 58 // Notification that the associated RenderView has navigated to a new page. | 60 // Translates the contents of |frame| if it has not already been translated |
| 59 void NavigatedToNewPage(); | 61 // and if the main frame was previously translated. |
| 62 // (Note this should not be called for the main frame, use TranslatePage for |
| 63 // it). |
| 64 void TranslateFrame(WebKit::WebFrame* frame); |
| 65 |
| 66 // Notification that the main frame of the current page has navigated. |
| 67 // This invalidates all our page states. |
| 68 void MainFrameNavigated(); |
| 69 |
| 70 // Returns true if the current page has been translated. |
| 71 bool IsPageTranslated(); |
| 60 | 72 |
| 61 // TextTranslator::Delegate implentation: | 73 // TextTranslator::Delegate implentation: |
| 62 virtual void TranslationError(int work_id, int error_id); | 74 virtual void TranslationError(int work_id, int error_id); |
| 63 virtual void TextTranslated( | 75 virtual void TextTranslated( |
| 64 int work_id, const std::vector<string16>& translated_text); | 76 int work_id, const std::vector<string16>& translated_text); |
| 65 | 77 |
| 66 private: | 78 private: |
| 67 // Comparator used in set of WebKit WebStrings. | 79 // Comparator used in set of WebKit WebStrings. |
| 68 struct WebStringCompare { | 80 struct WebStringCompare { |
| 69 bool operator()(const WebKit::WebString& s1, | 81 bool operator()(const WebKit::WebString& s1, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // The list of text zones in the current page, grouped in text zones (text | 141 // The list of text zones in the current page, grouped in text zones (text |
| 130 // nodes grouped in a same context). | 142 // nodes grouped in a same context). |
| 131 std::vector<NodeList*> text_nodes_; | 143 std::vector<NodeList*> text_nodes_; |
| 132 // The original text of the text nodes in |text_nodes_|. | 144 // The original text of the text nodes in |text_nodes_|. |
| 133 std::vector<TextChunks*> text_chunks_; | 145 std::vector<TextChunks*> text_chunks_; |
| 134 | 146 |
| 135 DISALLOW_COPY_AND_ASSIGN(PageTranslator); | 147 DISALLOW_COPY_AND_ASSIGN(PageTranslator); |
| 136 }; | 148 }; |
| 137 | 149 |
| 138 #endif // CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ | 150 #endif // CHROME_RENDERER_TRANSLATE_PAGE_TRANSLATOR_H_ |
| OLD | NEW |