Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ | 5 #ifndef CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ |
| 6 #define CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ | 6 #define CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| 12 #include "base/string16.h" | 11 #include "base/string16.h" |
| 13 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 14 #include "content/public/renderer/render_process_observer.h" | 13 #include "content/public/renderer/render_process_observer.h" |
| 15 #include "ipc/ipc_platform_file.h" | 14 #include "ipc/ipc_platform_file.h" |
| 16 | 15 |
| 17 namespace file_util { | |
| 18 class MemoryMappedFile; | |
| 19 } | |
| 20 | |
| 21 typedef struct _HyphenDict HyphenDict; | 16 typedef struct _HyphenDict HyphenDict; |
| 22 | 17 |
| 23 namespace content { | 18 namespace content { |
| 24 class RenderThread; | 19 class RenderThread; |
| 25 | 20 |
| 26 // A class that hyphenates a word. This class encapsulates the hyphen library | 21 // A class that hyphenates a word. This class encapsulates the hyphen library |
| 27 // and manages resources used by the library. When this class uses a huge | 22 // and manages resources used by the library. When this class uses a huge |
| 28 // dictionary, it takes lots of memory (~1.3MB for English). A renderer should | 23 // dictionary, it takes lots of memory (~1.3MB for English). A renderer should |
| 29 // create this object only when it renders a page that needs hyphenation and | 24 // create this object only when it renders a page that needs hyphenation and |
| 30 // deletes it when it moves to a page that does not need hyphenation. | 25 // deletes it when it moves to a page that does not need hyphenation. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 51 | 46 |
| 52 // RenderProcessObserver implementation. | 47 // RenderProcessObserver implementation. |
| 53 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | 48 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; |
| 54 | 49 |
| 55 private: | 50 private: |
| 56 void OnSetDictionary(IPC::PlatformFileForTransit rule_file); | 51 void OnSetDictionary(IPC::PlatformFileForTransit rule_file); |
| 57 | 52 |
| 58 // The dictionary used by the hyphen library. | 53 // The dictionary used by the hyphen library. |
| 59 HyphenDict* dictionary_; | 54 HyphenDict* dictionary_; |
| 60 | 55 |
| 61 // The dictionary file and its memory-mapping object. (Our copy of the hyphen | |
| 62 // library uses a memory-mapped file opened by a browser so renderers can use | |
| 63 // it without opening the file.) | |
| 64 string16 locale_; | 56 string16 locale_; |
| 65 base::PlatformFile rule_file_; | 57 |
| 66 scoped_ptr<file_util::MemoryMappedFile> rule_map_; | 58 FILE* dictionary_file_; |
|
darin (slow to review)
2013/02/15 18:16:40
nit: You could use ScopedStdioHandle here.
Paweł Hajdan Jr.
2013/02/19 13:00:12
Done.
| |
| 67 | 59 |
| 68 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same | 60 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same |
| 69 // word multiple times to find the best hyphenation point when it finds a line | 61 // word multiple times to find the best hyphenation point when it finds a line |
| 70 // break. On the other hand, the hyphen library returns all hyphenation points | 62 // break. On the other hand, the hyphen library returns all hyphenation points |
| 71 // for a word. This class caches the hyphenation points returned by the hyphen | 63 // for a word. This class caches the hyphenation points returned by the hyphen |
| 72 // library to avoid calling the library multiple times. | 64 // library to avoid calling the library multiple times. |
| 73 string16 word_; | 65 string16 word_; |
| 74 bool result_; | 66 bool result_; |
| 75 std::vector<int> hyphen_offsets_; | 67 std::vector<int> hyphen_offsets_; |
| 76 | 68 |
| 77 DISALLOW_COPY_AND_ASSIGN(Hyphenator); | 69 DISALLOW_COPY_AND_ASSIGN(Hyphenator); |
| 78 }; | 70 }; |
| 79 | 71 |
| 80 } // namespace content | 72 } // namespace content |
| 81 | 73 |
| 82 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ | 74 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ |
| OLD | NEW |