| 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" | 10 #include "base/memory/scoped_handle.h" |
| 11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/public/renderer/render_process_observer.h" | 14 #include "content/public/renderer/render_process_observer.h" |
| 15 #include "ipc/ipc_platform_file.h" | 15 #include "ipc/ipc_platform_file.h" |
| 16 | 16 |
| 17 namespace file_util { | |
| 18 class MemoryMappedFile; | |
| 19 } | |
| 20 | |
| 21 typedef struct _HyphenDict HyphenDict; | 17 typedef struct _HyphenDict HyphenDict; |
| 22 | 18 |
| 23 namespace content { | 19 namespace content { |
| 24 class RenderThread; | 20 class RenderThread; |
| 25 | 21 |
| 26 // A class that hyphenates a word. This class encapsulates the hyphen library | 22 // 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 | 23 // 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 | 24 // 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 | 25 // 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. | 26 // deletes it when it moves to a page that does not need hyphenation. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 | 47 |
| 52 // RenderProcessObserver implementation. | 48 // RenderProcessObserver implementation. |
| 53 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | 49 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; |
| 54 | 50 |
| 55 private: | 51 private: |
| 56 void OnSetDictionary(IPC::PlatformFileForTransit rule_file); | 52 void OnSetDictionary(IPC::PlatformFileForTransit rule_file); |
| 57 | 53 |
| 58 // The dictionary used by the hyphen library. | 54 // The dictionary used by the hyphen library. |
| 59 HyphenDict* dictionary_; | 55 HyphenDict* dictionary_; |
| 60 | 56 |
| 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_; | 57 string16 locale_; |
| 65 base::PlatformFile rule_file_; | 58 |
| 66 scoped_ptr<file_util::MemoryMappedFile> rule_map_; | 59 ScopedStdioHandle dictionary_file_; |
| 67 | 60 |
| 68 // A cached result. WebKit often calls ComputeLastHyphenLocation with the same | 61 // 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 | 62 // 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 | 63 // 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 | 64 // for a word. This class caches the hyphenation points returned by the hyphen |
| 72 // library to avoid calling the library multiple times. | 65 // library to avoid calling the library multiple times. |
| 73 string16 word_; | 66 string16 word_; |
| 74 bool result_; | 67 bool result_; |
| 75 std::vector<int> hyphen_offsets_; | 68 std::vector<int> hyphen_offsets_; |
| 76 | 69 |
| 77 DISALLOW_COPY_AND_ASSIGN(Hyphenator); | 70 DISALLOW_COPY_AND_ASSIGN(Hyphenator); |
| 78 }; | 71 }; |
| 79 | 72 |
| 80 } // namespace content | 73 } // namespace content |
| 81 | 74 |
| 82 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ | 75 #endif // CONTENT_RENDERER_HYPHENATOR_HYPHENATOR_H_ |
| OLD | NEW |