Commit 75d78246 authored by tfarina@chromium.org's avatar tfarina@chromium.org

Move BiDiLineIterator to base/i18n/ directory.

BUG=23581
TEST=trybots

Review URL: http://codereview.chromium.org/6249007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71884 0039d316-1c4b-4281-b951-d872f2087c98
parent f6ab5725
# Copyright (c) 2010 The Chromium Authors. All rights reserved. # Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -159,7 +159,6 @@ ...@@ -159,7 +159,6 @@
'../ui/base/win/window_impl.h', '../ui/base/win/window_impl.h',
'active_window_watcher_x.cc', 'active_window_watcher_x.cc',
'active_window_watcher_x.h', 'active_window_watcher_x.h',
'bidi_line_iterator.cc',
'data_pack.cc', 'data_pack.cc',
'data_pack.h', 'data_pack.h',
'event_synthesis_gtk.cc', 'event_synthesis_gtk.cc',
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
'base', 'base',
], ],
'sources': [ 'sources': [
'i18n/bidi_line_iterator.cc',
'i18n/bidi_line_iterator.h',
'i18n/break_iterator.cc', 'i18n/break_iterator.cc',
'i18n/break_iterator.h', 'i18n/break_iterator.h',
'i18n/char_iterator.cc', 'i18n/char_iterator.cc',
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "app/bidi_line_iterator.h" #include "base/i18n/bidi_line_iterator.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h" namespace base {
namespace i18n {
BiDiLineIterator::BiDiLineIterator() : bidi_(NULL) {
}
BiDiLineIterator::~BiDiLineIterator() { BiDiLineIterator::~BiDiLineIterator() {
if (bidi_) { if (bidi_) {
...@@ -15,9 +19,9 @@ BiDiLineIterator::~BiDiLineIterator() { ...@@ -15,9 +19,9 @@ BiDiLineIterator::~BiDiLineIterator() {
} }
} }
UBool BiDiLineIterator::Open(const string16& text, bool BiDiLineIterator::Open(const string16& text,
bool right_to_left, bool right_to_left,
bool url) { bool url) {
DCHECK(bidi_ == NULL); DCHECK(bidi_ == NULL);
UErrorCode error = U_ZERO_ERROR; UErrorCode error = U_ZERO_ERROR;
bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error); bidi_ = ubidi_openSized(static_cast<int>(text.length()), 0, &error);
...@@ -28,7 +32,7 @@ UBool BiDiLineIterator::Open(const string16& text, ...@@ -28,7 +32,7 @@ UBool BiDiLineIterator::Open(const string16& text,
ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()), ubidi_setPara(bidi_, text.data(), static_cast<int>(text.length()),
right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, right_to_left ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
NULL, &error); NULL, &error);
return U_SUCCESS(error); return U_SUCCESS(error) ? true : false;
} }
int BiDiLineIterator::CountRuns() { int BiDiLineIterator::CountRuns() {
...@@ -51,3 +55,6 @@ void BiDiLineIterator::GetLogicalRun(int start, ...@@ -51,3 +55,6 @@ void BiDiLineIterator::GetLogicalRun(int start,
DCHECK(bidi_ != NULL); DCHECK(bidi_ != NULL);
ubidi_getLogicalRun(bidi_, start, end, level); ubidi_getLogicalRun(bidi_, start, end, level);
} }
} // namespace i18n
} // namespace base
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef APP_BIDI_LINE_ITERATOR_H_ #ifndef BASE_I18N_BIDI_LINE_ITERATOR_H_
#define APP_BIDI_LINE_ITERATOR_H_ #define BASE_I18N_BIDI_LINE_ITERATOR_H_
#pragma once #pragma once
#include <string>
#include "unicode/ubidi.h" #include "unicode/ubidi.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/string16.h" #include "base/string16.h"
namespace base {
namespace i18n {
// A simple wrapper class for the bidirectional iterator of ICU. // A simple wrapper class for the bidirectional iterator of ICU.
// This class uses the bidirectional iterator of ICU to split a line of // This class uses the bidirectional iterator of ICU to split a line of
// bidirectional texts into visual runs in its display order. // bidirectional texts into visual runs in its display order.
class BiDiLineIterator { class BiDiLineIterator {
public: public:
BiDiLineIterator() : bidi_(NULL) { } BiDiLineIterator();
~BiDiLineIterator(); ~BiDiLineIterator();
// Initializes the bidirectional iterator with the specified text. Returns // Initializes the bidirectional iterator with the specified text. Returns
// whether initialization succeeded. // whether initialization succeeded.
UBool Open(const string16& text, bool right_to_left, bool url); bool Open(const string16& text, bool right_to_left, bool url);
// Returns the number of visual runs in the text, or zero on error. // Returns the number of visual runs in the text, or zero on error.
int CountRuns(); int CountRuns();
...@@ -40,4 +41,7 @@ class BiDiLineIterator { ...@@ -40,4 +41,7 @@ class BiDiLineIterator {
DISALLOW_COPY_AND_ASSIGN(BiDiLineIterator); DISALLOW_COPY_AND_ASSIGN(BiDiLineIterator);
}; };
#endif // APP_BIDI_LINE_ITERATOR_H_ } // namespace i18n
} // namespace base
#endif // BASE_I18N_BIDI_LINE_ITERATOR_H_
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h" #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h"
#include "app/bidi_line_iterator.h"
#include "app/l10n_util.h" #include "app/l10n_util.h"
#include "app/resource_bundle.h" #include "app/resource_bundle.h"
#include "app/text_elider.h" #include "app/text_elider.h"
#include "app/theme_provider.h" #include "app/theme_provider.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/i18n/bidi_line_iterator.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h" #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
...@@ -558,7 +558,7 @@ int AutocompleteResultView::DrawString( ...@@ -558,7 +558,7 @@ int AutocompleteResultView::DrawString(
// worry about whether our eliding might change the visual display in // worry about whether our eliding might change the visual display in
// unintended ways, e.g. by removing directional markings or by adding an // unintended ways, e.g. by removing directional markings or by adding an
// ellipsis that's not enclosed in appropriate markings. // ellipsis that's not enclosed in appropriate markings.
BiDiLineIterator bidi_line; base::i18n::BiDiLineIterator bidi_line;
if (!bidi_line.Open(WideToUTF16Hack(text), base::i18n::IsRTL(), is_url)) if (!bidi_line.Open(WideToUTF16Hack(text), base::i18n::IsRTL(), is_url))
return x; return x;
const int num_runs = bidi_line.CountRuns(); const int num_runs = bidi_line.CountRuns();
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "views/view_text_utils.h" #include "views/view_text_utils.h"
#include "app/bidi_line_iterator.h" #include "base/i18n/bidi_line_iterator.h"
#include "base/i18n/break_iterator.h" #include "base/i18n/break_iterator.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -31,7 +31,7 @@ void DrawTextAndPositionUrl(gfx::Canvas* canvas, ...@@ -31,7 +31,7 @@ void DrawTextAndPositionUrl(gfx::Canvas* canvas,
// a run is a sequence of words that share the same directionality. We // a run is a sequence of words that share the same directionality. We
// initialize a bidirectional ICU line iterator and split the text into // initialize a bidirectional ICU line iterator and split the text into
// runs that are either strictly LTR or strictly RTL, with no mix. // runs that are either strictly LTR or strictly RTL, with no mix.
BiDiLineIterator bidi_line; base::i18n::BiDiLineIterator bidi_line;
if (!bidi_line.Open(WideToUTF16Hack(text), true, false)) if (!bidi_line.Open(WideToUTF16Hack(text), true, false))
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment