From 4c1bd635cf5de020499655d545e543583e3f7e21 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Tue, 29 Nov 2011 12:07:10 +0000 Subject: views: Move label and link files to ui/views/controls/. BUG=104039 R=ben@chromium.org TBR=stevenjb@chromium.org Review URL: http://codereview.chromium.org/8729013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111917 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/drop_shadow_label.h | 2 +- chrome/browser/chromeos/frame/bubble_frame_view.cc | 2 +- chrome/browser/chromeos/frame/panel_controller.cc | 2 +- .../chromeos/input_method/candidate_window.cc | 2 +- chrome/browser/chromeos/login/background_view.cc | 2 +- chrome/browser/chromeos/login/captcha_view.cc | 2 +- chrome/browser/chromeos/login/helper.cc | 2 +- chrome/browser/chromeos/login/message_bubble.cc | 4 +- chrome/browser/chromeos/login/message_bubble.h | 2 +- .../chromeos/login/password_changed_view.cc | 2 +- chrome/browser/chromeos/login/screen_lock_view.cc | 2 +- .../browser/chromeos/login/screen_locker_tester.cc | 2 +- chrome/browser/chromeos/login/take_photo_view.cc | 2 +- chrome/browser/chromeos/login/user_view.cc | 6 +- chrome/browser/chromeos/login/user_view.h | 2 +- chrome/browser/chromeos/login/username_view.h | 2 +- chrome/browser/chromeos/login/web_page_view.cc | 2 +- .../browser/chromeos/notifications/balloon_view.cc | 2 +- chrome/browser/chromeos/options/vpn_config_view.cc | 2 +- .../browser/chromeos/options/wifi_config_view.cc | 2 +- .../browser/chromeos/status/status_area_bubble.cc | 2 +- chrome/browser/first_run/try_chrome_dialog_view.cc | 2 +- chrome/browser/first_run/try_chrome_dialog_view.h | 2 +- chrome/browser/speech/speech_input_bubble_views.cc | 6 +- chrome/browser/ui/input_window_dialog_win.cc | 2 +- .../browser/ui/panels/panel_browser_frame_view.cc | 2 +- chrome/browser/ui/panels/panel_browser_view.cc | 2 +- .../ui/panels/panel_browser_view_browsertest.cc | 4 +- chrome/browser/ui/views/about_chrome_view.cc | 2 +- chrome/browser/ui/views/about_chrome_view.h | 4 +- .../autocomplete_popup_contents_view.cc | 2 +- chrome/browser/ui/views/avatar_menu_bubble_view.cc | 4 +- chrome/browser/ui/views/avatar_menu_bubble_view.h | 2 +- .../bookmarks/bookmark_bar_instructions_view.cc | 4 +- .../bookmarks/bookmark_bar_instructions_view.h | 2 +- .../ui/views/bookmarks/bookmark_bar_view.cc | 2 +- .../ui/views/bookmarks/bookmark_bubble_view.cc | 4 +- .../ui/views/bookmarks/bookmark_bubble_view.h | 2 +- .../ui/views/bookmarks/bookmark_editor_view.cc | 2 +- chrome/browser/ui/views/collected_cookies_win.cc | 2 +- chrome/browser/ui/views/confirm_bubble_view.cc | 4 +- chrome/browser/ui/views/confirm_bubble_view.h | 2 +- .../ui/views/content_setting_bubble_contents.cc | 4 +- .../ui/views/content_setting_bubble_contents.h | 2 +- chrome/browser/ui/views/cookie_info_view.cc | 2 +- .../ui/views/create_application_shortcut_view.cc | 2 +- .../ui/views/critical_notification_bubble_view.cc | 2 +- chrome/browser/ui/views/database_info_view.cc | 2 +- chrome/browser/ui/views/default_search_view.cc | 2 +- .../download/download_in_progress_dialog_view.cc | 2 +- .../ui/views/download/download_item_view.cc | 2 +- .../ui/views/download/download_shelf_view.cc | 2 +- .../ui/views/download/download_shelf_view.h | 2 +- .../browser/ui/views/edit_search_engine_dialog.cc | 2 +- .../extensions/extension_install_dialog_view.cc | 6 +- .../views/extensions/extension_installed_bubble.cc | 6 +- .../extensions/extension_uninstall_dialog_view.cc | 2 +- chrome/browser/ui/views/find_bar_view.cc | 2 +- chrome/browser/ui/views/first_run_bubble.cc | 2 +- .../ui/views/first_run_search_engine_view.cc | 2 +- .../ui/views/fullscreen_exit_bubble_views.cc | 4 +- chrome/browser/ui/views/generic_info_view.cc | 2 +- .../browser/ui/views/generic_info_view_unittest.cc | 2 +- .../browser/ui/views/global_error_bubble_view.cc | 2 +- chrome/browser/ui/views/hung_renderer_view.cc | 2 +- .../ui/views/importer/import_lock_dialog_view.cc | 2 +- .../views/importer/import_progress_dialog_view.cc | 2 +- chrome/browser/ui/views/indexed_db_info_view.cc | 2 +- .../ui/views/infobars/after_translate_infobar.cc | 2 +- .../ui/views/infobars/before_translate_infobar.cc | 2 +- .../browser/ui/views/infobars/confirm_infobar.cc | 4 +- chrome/browser/ui/views/infobars/confirm_infobar.h | 2 +- chrome/browser/ui/views/infobars/infobar_view.cc | 4 +- chrome/browser/ui/views/infobars/link_infobar.cc | 4 +- chrome/browser/ui/views/infobars/link_infobar.h | 2 +- .../ui/views/infobars/translate_infobar_base.cc | 2 +- .../ui/views/infobars/translate_message_infobar.cc | 2 +- chrome/browser/ui/views/instant_confirm_view.cc | 4 +- chrome/browser/ui/views/instant_confirm_view.h | 2 +- chrome/browser/ui/views/local_storage_info_view.cc | 2 +- .../ui/views/local_storage_set_item_info_view.cc | 2 +- .../views/location_bar/icon_label_bubble_view.cc | 2 +- .../ui/views/location_bar/keyword_hint_view.cc | 2 +- .../ui/views/location_bar/location_bar_view.cc | 2 +- .../ui/views/location_bar/selected_keyword_view.h | 2 +- .../ui/views/location_bar/suggested_text_view.h | 2 +- chrome/browser/ui/views/login_view.cc | 2 +- .../browser/ui/views/notifications/balloon_view.h | 2 +- chrome/browser/ui/views/page_info_bubble_view.cc | 4 +- chrome/browser/ui/views/page_info_bubble_view.h | 2 +- chrome/browser/ui/views/sad_tab_view.cc | 4 +- chrome/browser/ui/views/sad_tab_view.h | 2 +- .../ui/views/ssl_client_certificate_selector.cc | 2 +- chrome/browser/ui/views/status_bubble_views.cc | 2 +- chrome/browser/ui/views/task_manager_view.cc | 4 +- chrome/browser/ui/views/uninstall_view.cc | 2 +- chrome/browser/ui/views/web_intent_picker_view.cc | 2 +- chrome/browser/ui/views/wrench_menu.cc | 2 +- ui/aura_shell/examples/bubble.cc | 2 +- ui/views/controls/button/checkbox.cc | 2 +- ui/views/controls/label.cc | 503 +++++++++++++ ui/views/controls/label.h | 289 ++++++++ ui/views/controls/label_unittest.cc | 811 +++++++++++++++++++++ ui/views/controls/link.cc | 200 +++++ ui/views/controls/link.h | 78 ++ ui/views/controls/link_listener.h | 24 + .../controls/textfield/native_textfield_win.cc | 2 +- ui/views/examples/bubble_example.cc | 2 +- ui/views/examples/examples_main.cc | 2 +- ui/views/examples/link_example.cc | 2 +- ui/views/examples/link_example.h | 2 +- ui/views/examples/native_theme_button_example.cc | 2 +- ui/views/examples/text_example.cc | 2 +- ui/views/examples/textfield_example.cc | 2 +- ui/views/focus/focus_traversal_unittest.cc | 4 +- .../touchui/touch_selection_controller_impl.cc | 2 +- ui/views/widget/tooltip_manager_views.h | 2 +- views/controls/label.cc | 503 ------------- views/controls/label.h | 289 -------- views/controls/label_unittest.cc | 811 --------------------- views/controls/link.cc | 200 ----- views/controls/link.h | 78 -- views/controls/link_listener.h | 24 - views/controls/message_box_view.cc | 2 +- views/view_text_utils.cc | 4 +- views/views.gyp | 12 +- 126 files changed, 2050 insertions(+), 2050 deletions(-) create mode 100644 ui/views/controls/label.cc create mode 100644 ui/views/controls/label.h create mode 100644 ui/views/controls/label_unittest.cc create mode 100644 ui/views/controls/link.cc create mode 100644 ui/views/controls/link.h create mode 100644 ui/views/controls/link_listener.h delete mode 100644 views/controls/label.cc delete mode 100644 views/controls/label.h delete mode 100644 views/controls/label_unittest.cc delete mode 100644 views/controls/link.cc delete mode 100644 views/controls/link.h delete mode 100644 views/controls/link_listener.h diff --git a/chrome/browser/chromeos/drop_shadow_label.h b/chrome/browser/chromeos/drop_shadow_label.h index 1be105d..e64f12d 100644 --- a/chrome/browser/chromeos/drop_shadow_label.h +++ b/chrome/browser/chromeos/drop_shadow_label.h @@ -7,7 +7,7 @@ #pragma once #include "ui/gfx/font.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" namespace chromeos { diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.cc b/chrome/browser/chromeos/frame/bubble_frame_view.cc index 4eb6fe6..9691fa9 100644 --- a/chrome/browser/chromeos/frame/bubble_frame_view.cc +++ b/chrome/browser/chromeos/frame/bubble_frame_view.cc @@ -20,9 +20,9 @@ #include "ui/gfx/path.h" #include "ui/gfx/rect.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" -#include "views/controls/label.h" #include "views/controls/throbber.h" namespace { diff --git a/chrome/browser/chromeos/frame/panel_controller.cc b/chrome/browser/chromeos/frame/panel_controller.cc index 85e42e4..4de9fda 100644 --- a/chrome/browser/chromeos/frame/panel_controller.cc +++ b/chrome/browser/chromeos/frame/panel_controller.cc @@ -29,10 +29,10 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas_skia.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/events/event.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" #include "views/painter.h" #include "views/view.h" diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index b1416ed..85078ff 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -23,13 +23,13 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/screen.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/events/event.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/widget/widget.h" #include "ui/views/window/non_client_view.h" -#include "views/controls/label.h" namespace chromeos { namespace input_method { diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 1a0f91d..16370c2 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -32,8 +32,8 @@ #include "ui/base/x/x11_util.h" #include "ui/gfx/gtk_util.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #if defined(TOOLKIT_USES_GTK) #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" diff --git a/chrome/browser/chromeos/login/captcha_view.cc b/chrome/browser/chromeos/login/captcha_view.cc index b534c2c..266f041 100644 --- a/chrome/browser/chromeos/login/captcha_view.cc +++ b/chrome/browser/chromeos/login/captcha_view.cc @@ -16,13 +16,13 @@ #include "grit/locale_settings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/background.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" using views::Label; using views::Textfield; diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index 9d087fa..5c0d9b5 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -17,9 +17,9 @@ #include "ui/gfx/canvas_skia.h" #include "ui/gfx/screen.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #include "views/controls/throbber.h" #include "views/painter.h" diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc index fa1a1cc..f526dd9 100644 --- a/chrome/browser/chromeos/login/message_bubble.cc +++ b/chrome/browser/chromeos/login/message_bubble.cc @@ -13,11 +13,11 @@ #include "grit/theme_resources_standard.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" namespace chromeos { diff --git a/chrome/browser/chromeos/login/message_bubble.h b/chrome/browser/chromeos/login/message_bubble.h index 99d3bab..ecdf775 100644 --- a/chrome/browser/chromeos/login/message_bubble.h +++ b/chrome/browser/chromeos/login/message_bubble.h @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/ui/views/bubble/bubble.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" #include "views/view.h" #if defined(TOOLKIT_USES_GTK) diff --git a/chrome/browser/chromeos/login/password_changed_view.cc b/chrome/browser/chromeos/login/password_changed_view.cc index c0692de..c20d018 100644 --- a/chrome/browser/chromeos/login/password_changed_view.cc +++ b/chrome/browser/chromeos/login/password_changed_view.cc @@ -14,11 +14,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/radio_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" using views::Button; using views::GridLayout; diff --git a/chrome/browser/chromeos/login/screen_lock_view.cc b/chrome/browser/chromeos/login/screen_lock_view.cc index 98aef5f..e55e8a9 100644 --- a/chrome/browser/chromeos/login/screen_lock_view.cc +++ b/chrome/browser/chromeos/login/screen_lock_view.cc @@ -19,6 +19,7 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/native_textfield_wrapper.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" @@ -26,7 +27,6 @@ #include "views/background.h" #include "views/border.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace chromeos { diff --git a/chrome/browser/chromeos/login/screen_locker_tester.cc b/chrome/browser/chromeos/login/screen_locker_tester.cc index d5ac67f..bcfe0c9 100644 --- a/chrome/browser/chromeos/login/screen_locker_tester.cc +++ b/chrome/browser/chromeos/login/screen_locker_tester.cc @@ -13,10 +13,10 @@ #include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/screen_locker_views.h" #include "ui/views/controls/button/button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/events/event.h" #include "ui/views/widget/root_view.h" -#include "views/controls/label.h" namespace chromeos { diff --git a/chrome/browser/chromeos/login/take_photo_view.cc b/chrome/browser/chromeos/login/take_photo_view.cc index 58d6c37..f1c2ef1 100644 --- a/chrome/browser/chromeos/login/take_photo_view.cc +++ b/chrome/browser/chromeos/login/take_photo_view.cc @@ -13,11 +13,11 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "views/background.h" #include "views/border.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" #include "views/controls/throbber.h" namespace { diff --git a/chrome/browser/chromeos/login/user_view.cc b/chrome/browser/chromeos/login/user_view.cc index a7d5020..914d0a9 100644 --- a/chrome/browser/chromeos/login/user_view.cc +++ b/chrome/browser/chromeos/login/user_view.cc @@ -19,11 +19,11 @@ #include "ui/gfx/gtk_util.h" #include "ui/gfx/rect.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "views/background.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" namespace { diff --git a/chrome/browser/chromeos/login/user_view.h b/chrome/browser/chromeos/login/user_view.h index 929468c..a9333de 100644 --- a/chrome/browser/chromeos/login/user_view.h +++ b/chrome/browser/chromeos/login/user_view.h @@ -9,7 +9,7 @@ #include #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" #include "views/view.h" class SkBitmap; diff --git a/chrome/browser/chromeos/login/username_view.h b/chrome/browser/chromeos/login/username_view.h index ea9feaa..d6ec6d0 100644 --- a/chrome/browser/chromeos/login/username_view.h +++ b/chrome/browser/chromeos/login/username_view.h @@ -8,8 +8,8 @@ #include -#include "views/controls/label.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/views/controls/label.h" // Forward declaration. namespace gfx { diff --git a/chrome/browser/chromeos/login/web_page_view.cc b/chrome/browser/chromeos/login/web_page_view.cc index 8b724c7..54dac4f 100644 --- a/chrome/browser/chromeos/login/web_page_view.cc +++ b/chrome/browser/chromeos/login/web_page_view.cc @@ -23,9 +23,9 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/views/controls/label.h" #include "views/background.h" #include "views/border.h" -#include "views/controls/label.h" #include "views/controls/throbber.h" using base::TimeDelta; diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc index 8f7400b..646a2c8 100644 --- a/chrome/browser/chromeos/notifications/balloon_view.cc +++ b/chrome/browser/chromeos/notifications/balloon_view.cc @@ -33,13 +33,13 @@ #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_runner.h" #include "ui/views/controls/menu/view_menu_delegate.h" #include "ui/views/widget/widget.h" #include "views/background.h" -#include "views/controls/label.h" namespace { // Menu commands diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc index 2e31806..85a1512 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.cc +++ b/chrome/browser/chromeos/options/vpn_config_view.cc @@ -18,10 +18,10 @@ #include "ui/base/models/combobox_model.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index 9d15680..31f84c1 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -18,10 +18,10 @@ #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" namespace chromeos { diff --git a/chrome/browser/chromeos/status/status_area_bubble.cc b/chrome/browser/chromeos/status/status_area_bubble.cc index e210b47..1893bdd 100644 --- a/chrome/browser/chromeos/status/status_area_bubble.cc +++ b/chrome/browser/chromeos/status/status_area_bubble.cc @@ -6,8 +6,8 @@ #include "chrome/browser/ui/views/window.h" #include "ui/base/accessibility/accessible_view_state.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/first_run/try_chrome_dialog_view.cc b/chrome/browser/first_run/try_chrome_dialog_view.cc index 53f4563..c4df79b 100644 --- a/chrome/browser/first_run/try_chrome_dialog_view.cc +++ b/chrome/browser/first_run/try_chrome_dialog_view.cc @@ -21,11 +21,11 @@ #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/link.h" namespace { diff --git a/chrome/browser/first_run/try_chrome_dialog_view.h b/chrome/browser/first_run/try_chrome_dialog_view.h index 40af6f7..9724987 100644 --- a/chrome/browser/first_run/try_chrome_dialog_view.h +++ b/chrome/browser/first_run/try_chrome_dialog_view.h @@ -10,7 +10,7 @@ #include "base/compiler_specific.h" #include "ui/gfx/native_widget_types.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class ProcessSingleton; diff --git a/chrome/browser/speech/speech_input_bubble_views.cc b/chrome/browser/speech/speech_input_bubble_views.cc index 21e4a0e..0b9185f 100644 --- a/chrome/browser/speech/speech_input_bubble_views.cc +++ b/chrome/browser/speech/speech_input_bubble_views.cc @@ -21,11 +21,11 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/layout/layout_constants.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" namespace { diff --git a/chrome/browser/ui/input_window_dialog_win.cc b/chrome/browser/ui/input_window_dialog_win.cc index e406d70..3a63e1d 100644 --- a/chrome/browser/ui/input_window_dialog_win.cc +++ b/chrome/browser/ui/input_window_dialog_win.cc @@ -13,13 +13,13 @@ #include "chrome/browser/ui/webui/input_window_dialog_webui.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc index 6ea05e1..e749e0e 100644 --- a/chrome/browser/ui/panels/panel_browser_frame_view.cc +++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc @@ -29,11 +29,11 @@ #include "ui/gfx/screen.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_runner.h" #include "ui/views/widget/widget_delegate.h" -#include "views/controls/label.h" #include "views/painter.h" namespace { diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc index 2097753..0a887e2 100644 --- a/chrome/browser/ui/panels/panel_browser_view.cc +++ b/chrome/browser/ui/panels/panel_browser_view.cc @@ -17,8 +17,8 @@ #include "grit/chromium_strings.h" #include "ui/base/animation/slide_animation.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" namespace { // This value is experimental and subjective. diff --git a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc index c480c85..bda3a67 100644 --- a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc @@ -22,10 +22,10 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/controls/textfield/textfield.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" class PanelBrowserViewTest : public BasePanelBrowserTest { public: diff --git a/chrome/browser/ui/views/about_chrome_view.cc b/chrome/browser/ui/views/about_chrome_view.cc index 9d25605..db4b2fb 100644 --- a/chrome/browser/ui/views/about_chrome_view.cc +++ b/chrome/browser/ui/views/about_chrome_view.cc @@ -35,10 +35,10 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/link.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/link.h" #include "views/controls/throbber.h" #include "views/view_text_utils.h" #include "webkit/glue/webkit_glue.h" diff --git a/chrome/browser/ui/views/about_chrome_view.h b/chrome/browser/ui/views/about_chrome_view.h index 2394b74..fe5ddda 100644 --- a/chrome/browser/ui/views/about_chrome_view.h +++ b/chrome/browser/ui/views/about_chrome_view.h @@ -10,10 +10,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/window/dialog_delegate.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link_listener.h" #include "views/view.h" #if defined(OS_WIN) && !defined(USE_AURA) diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 63a610d..becb12d 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -31,11 +31,11 @@ #include "ui/gfx/path.h" #include "ui/views/bubble/bubble_border.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "unicode/ubidi.h" -#include "views/controls/label.h" #include "views/painter.h" #if defined(OS_WIN) diff --git a/chrome/browser/ui/views/avatar_menu_bubble_view.cc b/chrome/browser/ui/views/avatar_menu_bubble_view.cc index 8a0dcba..75945ee 100644 --- a/chrome/browser/ui/views/avatar_menu_bubble_view.cc +++ b/chrome/browser/ui/views/avatar_menu_bubble_view.cc @@ -22,9 +22,9 @@ #include "ui/gfx/image/image.h" #include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" #include "views/controls/separator.h" namespace { diff --git a/chrome/browser/ui/views/avatar_menu_bubble_view.h b/chrome/browser/ui/views/avatar_menu_bubble_view.h index 8dbf333..5d4ce32 100644 --- a/chrome/browser/ui/views/avatar_menu_bubble_view.h +++ b/chrome/browser/ui/views/avatar_menu_bubble_view.h @@ -13,7 +13,7 @@ #include "chrome/browser/profiles/avatar_menu_model_observer.h" #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class AvatarMenuModel; class Browser; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc index b4432d5..c354fe1 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc @@ -11,8 +11,8 @@ #include "chrome/browser/themes/theme_service.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -#include "views/controls/label.h" -#include "views/controls/link.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" namespace { diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h index bebb1fa..3e982a0 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/base/accessibility/accessible_view_state.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" #include "views/view.h" namespace views { diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 8d9d505..69c8c79 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -54,10 +54,10 @@ #include "ui/base/text/text_elider.h" #include "ui/gfx/canvas_skia.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/widget/tooltip_manager.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #include "views/drag_utils.h" #include "views/metrics.h" #include "views/view_constants.h" diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 97a73b2..d367d50 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -25,13 +25,13 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/events/event.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" -#include "views/controls/link.h" using views::ColumnSet; using views::GridLayout; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h index d77e799..ab4652d 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h @@ -14,7 +14,7 @@ #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/combobox/combobox_listener.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class Profile; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index 1479c27..08ec059 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -24,6 +24,7 @@ #include "net/base/net_util.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_2.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/focus/focus_manager.h" @@ -31,7 +32,6 @@ #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/background.h" -#include "views/controls/label.h" using views::GridLayout; diff --git a/chrome/browser/ui/views/collected_cookies_win.cc b/chrome/browser/ui/views/collected_cookies_win.cc index 4fa7b64..621fd1f 100644 --- a/chrome/browser/ui/views/collected_cookies_win.cc +++ b/chrome/browser/ui/views/collected_cookies_win.cc @@ -26,13 +26,13 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/color_utils.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/tabbed_pane/tabbed_pane.h" #include "ui/views/layout/box_layout.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace browser { diff --git a/chrome/browser/ui/views/confirm_bubble_view.cc b/chrome/browser/ui/views/confirm_bubble_view.cc index 6ee5393..88297e9 100644 --- a/chrome/browser/ui/views/confirm_bubble_view.cc +++ b/chrome/browser/ui/views/confirm_bubble_view.cc @@ -10,11 +10,11 @@ #include "ui/gfx/image/image.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" namespace { diff --git a/chrome/browser/ui/views/confirm_bubble_view.h b/chrome/browser/ui/views/confirm_bubble_view.h index c9c59aa..61d802e 100644 --- a/chrome/browser/ui/views/confirm_bubble_view.h +++ b/chrome/browser/ui/views/confirm_bubble_view.h @@ -10,7 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/views/bubble/bubble.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" #include "views/view.h" class ConfirmBubbleModel; diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc index b87f8df..41483ba 100644 --- a/chrome/browser/ui/views/content_setting_bubble_contents.cc +++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc @@ -26,11 +26,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" #include "views/controls/separator.h" #if defined(TOOLKIT_USES_GTK) diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.h b/chrome/browser/ui/views/content_setting_bubble_contents.h index 4f37021..473de22 100644 --- a/chrome/browser/ui/views/content_setting_bubble_contents.h +++ b/chrome/browser/ui/views/content_setting_bubble_contents.h @@ -15,7 +15,7 @@ #include "content/public/browser/notification_registrar.h" #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" // ContentSettingBubbleContents is used when the user turns on different kinds // of content blocking (e.g. "block images"). When viewing a page with blocked diff --git a/chrome/browser/ui/views/cookie_info_view.cc b/chrome/browser/ui/views/cookie_info_view.cc index d2ec8d6..d83aaf5 100644 --- a/chrome/browser/ui/views/cookie_info_view.cc +++ b/chrome/browser/ui/views/cookie_info_view.cc @@ -18,12 +18,12 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/tree/tree_view.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "views/border.h" -#include "views/controls/label.h" static const int kCookieInfoViewBorderSize = 1; static const int kCookieInfoViewInsetSize = 3; diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index 7c93578..a24ff40 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -36,11 +36,11 @@ #include "ui/gfx/canvas_skia.h" #include "ui/gfx/codec/png_codec.h" #include "ui/views/controls/button/checkbox.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/views/critical_notification_bubble_view.cc b/chrome/browser/ui/views/critical_notification_bubble_view.cc index 4f2ae48..31c7a07 100644 --- a/chrome/browser/ui/views/critical_notification_bubble_view.cc +++ b/chrome/browser/ui/views/critical_notification_bubble_view.cc @@ -20,11 +20,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/views/database_info_view.cc b/chrome/browser/ui/views/database_info_view.cc index 6ce812d..810f36d 100644 --- a/chrome/browser/ui/views/database_info_view.cc +++ b/chrome/browser/ui/views/database_info_view.cc @@ -12,10 +12,10 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/text/bytes_formatting.h" #include "ui/gfx/color_utils.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" static const int kDatabaseInfoViewBorderSize = 1; static const int kDatabaseInfoViewInsetSize = 3; diff --git a/chrome/browser/ui/views/default_search_view.cc b/chrome/browser/ui/views/default_search_view.cc index 16eb7bf..ad8aa13 100644 --- a/chrome/browser/ui/views/default_search_view.cc +++ b/chrome/browser/ui/views/default_search_view.cc @@ -23,12 +23,12 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_client_view.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/views/download/download_in_progress_dialog_view.cc b/chrome/browser/ui/views/download/download_in_progress_dialog_view.cc index f28635d9..159e739 100644 --- a/chrome/browser/ui/views/download/download_in_progress_dialog_view.cc +++ b/chrome/browser/ui/views/download/download_in_progress_dialog_view.cc @@ -19,10 +19,10 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/size.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/widget/widget.h" #include "views/border.h" -#include "views/controls/label.h" DownloadInProgressDialogView::DownloadInProgressDialogView(Browser* browser) : browser_(browser), diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index dfb4645..b6294b5 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -35,10 +35,10 @@ #include "ui/gfx/color_utils.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/widget/root_view.h" #include "ui/views/widget/widget.h" #include "unicode/uchar.h" -#include "views/controls/label.h" // TODO(paulg): These may need to be adjusted when download progress // animation is added, and also possibly to take into account diff --git a/chrome/browser/ui/views/download/download_shelf_view.cc b/chrome/browser/ui/views/download/download_shelf_view.cc index 01c54d4..b51f126 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.cc +++ b/chrome/browser/ui/views/download/download_shelf_view.cc @@ -27,9 +27,9 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/link.h" #include "views/background.h" #include "views/controls/image_view.h" -#include "views/controls/link.h" // Max number of download views we'll contain. Any time a view is added and // we already have this many download views, one is removed. diff --git a/chrome/browser/ui/views/download/download_shelf_view.h b/chrome/browser/ui/views/download/download_shelf_view.h index 892171d..1d88941 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.h +++ b/chrome/browser/ui/views/download/download_shelf_view.h @@ -13,8 +13,8 @@ #include "chrome/browser/download/download_shelf.h" #include "ui/base/animation/animation_delegate.h" #include "ui/views/controls/button/button.h" +#include "ui/views/controls/link_listener.h" #include "views/accessible_pane_view.h" -#include "views/controls/link_listener.h" #include "views/mouse_watcher.h" class BaseDownloadItemModel; diff --git a/chrome/browser/ui/views/edit_search_engine_dialog.cc b/chrome/browser/ui/views/edit_search_engine_dialog.cc index c410c03..db4086b 100644 --- a/chrome/browser/ui/views/edit_search_engine_dialog.cc +++ b/chrome/browser/ui/views/edit_search_engine_dialog.cc @@ -15,13 +15,13 @@ #include "grit/ui_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/table/table_view.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" using views::GridLayout; using views::ImageView; diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc index 6b1dc8e..c9dce08d 100644 --- a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc @@ -15,6 +15,9 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/layout/box_layout.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" @@ -22,9 +25,6 @@ #include "ui/views/window/dialog_delegate.h" #include "views/border.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" #include "views/controls/separator.h" #include "views/view.h" diff --git a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc index 7c77ad1..d03ced7 100644 --- a/chrome/browser/ui/views/extensions/extension_installed_bubble.cc +++ b/chrome/browser/ui/views/extensions/extension_installed_bubble.cc @@ -30,12 +30,12 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/layout/layout_constants.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" #include "views/view.h" namespace { diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc index b203b21..3a6e8fd 100644 --- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc @@ -16,11 +16,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" #include "views/view.h" namespace { diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index 04875ec..eb02c39 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -27,10 +27,10 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/widget/widget.h" #include "views/background.h" -#include "views/controls/label.h" // The amount of whitespace to have before the find button. static const int kWhiteSpaceAfterMatchCountLabel = 1; diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index 2989f1f..42a0353 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -21,11 +21,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/events/event.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" namespace { const int kAnchorVerticalOffset = -4; diff --git a/chrome/browser/ui/views/first_run_search_engine_view.cc b/chrome/browser/ui/views/first_run_search_engine_view.cc index 3443ca2..8b9426b 100644 --- a/chrome/browser/ui/views/first_run_search_engine_view.cc +++ b/chrome/browser/ui/views/first_run_search_engine_view.cc @@ -31,11 +31,11 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/views/controls/button/button.h" +#include "ui/views/controls/label.h" #include "ui/views/focus/accelerator_handler.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" #include "views/view_text_utils.h" namespace { diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc index 1f5a574..85c276a 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc @@ -18,11 +18,11 @@ #include "ui/gfx/screen.h" #include "ui/views/bubble/bubble_border.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/layout/box_layout.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/widget/widget.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" #include "views/view.h" #if defined(OS_WIN) diff --git a/chrome/browser/ui/views/generic_info_view.cc b/chrome/browser/ui/views/generic_info_view.cc index caedcf2..4ef36db 100644 --- a/chrome/browser/ui/views/generic_info_view.cc +++ b/chrome/browser/ui/views/generic_info_view.cc @@ -8,10 +8,10 @@ #include "base/utf_string_conversions.h" #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/color_utils.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" GenericInfoView::GenericInfoView(int number_of_rows) : number_of_rows_(number_of_rows), name_string_ids_(NULL) { diff --git a/chrome/browser/ui/views/generic_info_view_unittest.cc b/chrome/browser/ui/views/generic_info_view_unittest.cc index f3aa49c..babc540 100644 --- a/chrome/browser/ui/views/generic_info_view_unittest.cc +++ b/chrome/browser/ui/views/generic_info_view_unittest.cc @@ -9,9 +9,9 @@ #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" // This class is only used on windows for now. #if defined(OS_WIN) diff --git a/chrome/browser/ui/views/global_error_bubble_view.cc b/chrome/browser/ui/views/global_error_bubble_view.cc index 00e5861..4af108a 100644 --- a/chrome/browser/ui/views/global_error_bubble_view.cc +++ b/chrome/browser/ui/views/global_error_bubble_view.cc @@ -12,10 +12,10 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index 422bdb5..cbd8056 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -23,6 +23,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/table/group_table_view.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" @@ -30,7 +31,6 @@ #include "ui/views/window/client_view.h" #include "ui/views/window/dialog_delegate.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" class HungRendererDialogView; diff --git a/chrome/browser/ui/views/importer/import_lock_dialog_view.cc b/chrome/browser/ui/views/importer/import_lock_dialog_view.cc index 1190752..ce404f2 100644 --- a/chrome/browser/ui/views/importer/import_lock_dialog_view.cc +++ b/chrome/browser/ui/views/importer/import_lock_dialog_view.cc @@ -14,9 +14,9 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" // Default size of the dialog window. static const int kDefaultWindowWidth = 320; diff --git a/chrome/browser/ui/views/importer/import_progress_dialog_view.cc b/chrome/browser/ui/views/importer/import_progress_dialog_view.cc index 638ec33..d9a86c6 100644 --- a/chrome/browser/ui/views/importer/import_progress_dialog_view.cc +++ b/chrome/browser/ui/views/importer/import_progress_dialog_view.cc @@ -12,10 +12,10 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #include "views/controls/throbber.h" ImportProgressDialogView::ImportProgressDialogView( diff --git a/chrome/browser/ui/views/indexed_db_info_view.cc b/chrome/browser/ui/views/indexed_db_info_view.cc index fa451af..d6ef722 100644 --- a/chrome/browser/ui/views/indexed_db_info_view.cc +++ b/chrome/browser/ui/views/indexed_db_info_view.cc @@ -12,10 +12,10 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/text/bytes_formatting.h" #include "ui/gfx/color_utils.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" static const int kIndexedDBInfoViewBorderSize = 1; static const int kIndexedDBInfoViewInsetSize = 3; diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index f125333..55c4d73 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -9,8 +9,8 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" -#include "views/controls/label.h" AfterTranslateInfoBar::AfterTranslateInfoBar( InfoBarTabHelper* owner, diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index 2e2e6f8..f772c37 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -9,8 +9,8 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" -#include "views/controls/label.h" BeforeTranslateInfoBar::BeforeTranslateInfoBar( InfoBarTabHelper* owner, diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc index 484d1c2..6b2418b 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -8,8 +8,8 @@ #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/views/event_utils.h" #include "ui/views/controls/button/text_button.h" -#include "views/controls/label.h" -#include "views/controls/link.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" // ConfirmInfoBarDelegate ----------------------------------------------------- diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h index 9dd7aac..15762f6 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.h +++ b/chrome/browser/ui/views/infobars/confirm_infobar.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class ConfirmInfoBarDelegate; diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index 2fa3e94..f805591 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -27,14 +27,14 @@ #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_runner.h" #include "ui/views/focus/external_focus_tracker.h" #include "ui/views/widget/widget.h" #include "ui/views/window/non_client_view.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" #if defined(OS_WIN) #include "base/win/win_util.h" diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc index 5558446..60c4fb9 100644 --- a/chrome/browser/ui/views/infobars/link_infobar.cc +++ b/chrome/browser/ui/views/infobars/link_infobar.cc @@ -7,8 +7,8 @@ #include "base/logging.h" #include "chrome/browser/tab_contents/link_infobar_delegate.h" #include "chrome/browser/ui/views/event_utils.h" -#include "views/controls/label.h" -#include "views/controls/link.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" // LinkInfoBarDelegate -------------------------------------------------------- diff --git a/chrome/browser/ui/views/infobars/link_infobar.h b/chrome/browser/ui/views/infobars/link_infobar.h index 4c10924..bd993dd 100644 --- a/chrome/browser/ui/views/infobars/link_infobar.h +++ b/chrome/browser/ui/views/infobars/link_infobar.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class LinkInfoBarDelegate; diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc index ab8420b..02c58c5 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc @@ -14,7 +14,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas_skia.h" #include "ui/views/controls/button/menu_button.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" // TranslateInfoBarDelegate --------------------------------------------------- diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index 6c69382..2f2c787 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -6,7 +6,7 @@ #include "chrome/browser/translate/translate_infobar_delegate.h" #include "ui/views/controls/button/text_button.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" TranslateMessageInfoBar::TranslateMessageInfoBar( InfoBarTabHelper* owner, diff --git a/chrome/browser/ui/views/instant_confirm_view.cc b/chrome/browser/ui/views/instant_confirm_view.cc index 00bcd80..42f3c59 100644 --- a/chrome/browser/ui/views/instant_confirm_view.cc +++ b/chrome/browser/ui/views/instant_confirm_view.cc @@ -14,11 +14,11 @@ #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" -#include "views/controls/link.h" InstantConfirmView::InstantConfirmView(Profile* profile) : profile_(profile) { views::Label* description_label = new views::Label( diff --git a/chrome/browser/ui/views/instant_confirm_view.h b/chrome/browser/ui/views/instant_confirm_view.h index edf18e2..3cc4d43 100644 --- a/chrome/browser/ui/views/instant_confirm_view.h +++ b/chrome/browser/ui/views/instant_confirm_view.h @@ -8,8 +8,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/window/dialog_delegate.h" -#include "views/controls/link_listener.h" #include "views/view.h" class Profile; diff --git a/chrome/browser/ui/views/local_storage_info_view.cc b/chrome/browser/ui/views/local_storage_info_view.cc index 19c21b8..73a0cf3 100644 --- a/chrome/browser/ui/views/local_storage_info_view.cc +++ b/chrome/browser/ui/views/local_storage_info_view.cc @@ -12,10 +12,10 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/text/bytes_formatting.h" #include "ui/gfx/color_utils.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" static const int kLocalStorageInfoViewBorderSize = 1; static const int kLocalStorageInfoViewInsetSize = 3; diff --git a/chrome/browser/ui/views/local_storage_set_item_info_view.cc b/chrome/browser/ui/views/local_storage_set_item_info_view.cc index e9e19a2..2c9e2ac 100644 --- a/chrome/browser/ui/views/local_storage_set_item_info_view.cc +++ b/chrome/browser/ui/views/local_storage_set_item_info_view.cc @@ -10,10 +10,10 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/color_utils.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" static const int kLocalStorageSetItemInfoViewBorderSize = 1; static const int kLocalStorageSetItemInfoViewInsetSize = 3; diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc index 3333184..64dc948 100644 --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc @@ -9,8 +9,8 @@ #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/views/controls/label.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" // Amount of padding at the edges of the bubble. static const int kBubbleOuterPadding = LocationBarView::kEdgeItemPadding - diff --git a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc index f9f764c..9c0ac20 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc @@ -19,7 +19,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" // Amount of space to offset the tab image from the top of the view by. static const int kTabImageYOffset = 4; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 2c7f34f..14d6592 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -56,8 +56,8 @@ #include "ui/gfx/color_utils.h" #include "ui/gfx/image/image.h" #include "ui/gfx/skia_util.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/native_textfield_views.h" -#include "views/controls/label.h" #include "views/drag_utils.h" #if !defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/views/location_bar/selected_keyword_view.h b/chrome/browser/ui/views/location_bar/selected_keyword_view.h index ad4e2e1..9028ae0 100644 --- a/chrome/browser/ui/views/location_bar/selected_keyword_view.h +++ b/chrome/browser/ui/views/location_bar/selected_keyword_view.h @@ -10,7 +10,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" class Profile; namespace gfx { diff --git a/chrome/browser/ui/views/location_bar/suggested_text_view.h b/chrome/browser/ui/views/location_bar/suggested_text_view.h index 91a1f4f..feafb0c 100644 --- a/chrome/browser/ui/views/location_bar/suggested_text_view.h +++ b/chrome/browser/ui/views/location_bar/suggested_text_view.h @@ -8,7 +8,7 @@ #include "base/compiler_specific.h" #include "ui/base/animation/animation_delegate.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" class AutocompleteEditModel; diff --git a/chrome/browser/ui/views/login_view.cc b/chrome/browser/ui/views/login_view.cc index 0e3cbe0..3804376 100644 --- a/chrome/browser/ui/views/login_view.cc +++ b/chrome/browser/ui/views/login_view.cc @@ -11,11 +11,11 @@ #include "base/utf_string_conversions.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/root_view.h" -#include "views/controls/label.h" static const int kMessageWidth = 320; static const int kTextfieldStackHorizontalSpacing = 30; diff --git a/chrome/browser/ui/views/notifications/balloon_view.h b/chrome/browser/ui/views/notifications/balloon_view.h index e20d236..64e7cea 100644 --- a/chrome/browser/ui/views/notifications/balloon_view.h +++ b/chrome/browser/ui/views/notifications/balloon_view.h @@ -20,9 +20,9 @@ #include "ui/gfx/rect.h" #include "ui/gfx/size.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/view_menu_delegate.h" #include "ui/views/widget/widget_delegate.h" -#include "views/controls/label.h" #include "views/view.h" class BalloonCollection; diff --git a/chrome/browser/ui/views/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info_bubble_view.cc index ea6e5e0..fe3a5b8 100644 --- a/chrome/browser/ui/views/page_info_bubble_view.cc +++ b/chrome/browser/ui/views/page_info_bubble_view.cc @@ -21,11 +21,11 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/image/image.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/widget/widget.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" #include "views/controls/separator.h" namespace { diff --git a/chrome/browser/ui/views/page_info_bubble_view.h b/chrome/browser/ui/views/page_info_bubble_view.h index dc11086..8fd4bd5 100644 --- a/chrome/browser/ui/views/page_info_bubble_view.h +++ b/chrome/browser/ui/views/page_info_bubble_view.h @@ -11,7 +11,7 @@ #include "chrome/browser/page_info_model_observer.h" #include "ui/base/animation/slide_animation.h" #include "ui/views/bubble/bubble_delegate.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" class PageInfoBubbleView : public views::BubbleDelegateView, public PageInfoModelObserver, diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc index 0a88ff0..68d485d 100644 --- a/chrome/browser/ui/views/sad_tab_view.cc +++ b/chrome/browser/ui/views/sad_tab_view.cc @@ -18,10 +18,10 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/font.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/grid_layout.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" -#include "views/controls/link.h" static const int kPadding = 20; static const float kMessageSize = 0.65f; diff --git a/chrome/browser/ui/views/sad_tab_view.h b/chrome/browser/ui/views/sad_tab_view.h index 3aeff23..5cdd467 100644 --- a/chrome/browser/ui/views/sad_tab_view.h +++ b/chrome/browser/ui/views/sad_tab_view.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "ui/views/controls/button/button.h" -#include "views/controls/link_listener.h" +#include "ui/views/controls/link_listener.h" #include "views/view.h" class TabContents; diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector.cc b/chrome/browser/ui/views/ssl_client_certificate_selector.cc index d3782af..3beacb4 100644 --- a/chrome/browser/ui/views/ssl_client_certificate_selector.cc +++ b/chrome/browser/ui/views/ssl_client_certificate_selector.cc @@ -20,10 +20,10 @@ #include "ui/base/models/table_model_observer.h" #include "ui/gfx/native_widget_types.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/table/table_view.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" using content::BrowserThread; diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index 2b01a26..aa566f8 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -26,10 +26,10 @@ #include "ui/gfx/canvas_skia.h" #include "ui/gfx/point.h" #include "ui/gfx/screen.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/scrollbar/native_scroll_bar.h" #include "ui/views/widget/root_view.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" using views::Widget; diff --git a/chrome/browser/ui/views/task_manager_view.cc b/chrome/browser/ui/views/task_manager_view.cc index b8038e9..1f06ced 100644 --- a/chrome/browser/ui/views/task_manager_view.cc +++ b/chrome/browser/ui/views/task_manager_view.cc @@ -25,6 +25,8 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/models/table_model_observer.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/link.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/controls/menu/menu.h" #include "ui/views/controls/table/group_table_view.h" #include "ui/views/controls/table/table_view_observer.h" @@ -33,8 +35,6 @@ #include "ui/views/window/dialog_delegate.h" #include "views/background.h" #include "views/context_menu_controller.h" -#include "views/controls/link.h" -#include "views/controls/link_listener.h" // The task manager window default size. static const int kDefaultWidth = 460; diff --git a/chrome/browser/ui/views/uninstall_view.cc b/chrome/browser/ui/views/uninstall_view.cc index 58bc1d8..b7fc343 100644 --- a/chrome/browser/ui/views/uninstall_view.cc +++ b/chrome/browser/ui/views/uninstall_view.cc @@ -16,9 +16,9 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" -#include "views/controls/label.h" UninstallView::UninstallView(int* user_selection) : confirm_label_(NULL), diff --git a/chrome/browser/ui/views/web_intent_picker_view.cc b/chrome/browser/ui/views/web_intent_picker_view.cc index e98435e..2063533 100644 --- a/chrome/browser/ui/views/web_intent_picker_view.cc +++ b/chrome/browser/ui/views/web_intent_picker_view.cc @@ -22,9 +22,9 @@ #include "ui/gfx/canvas_skia.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/image_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" namespace { diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index cc0cdc9..89620d6 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -35,6 +35,7 @@ #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_config.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/controls/menu/menu_runner.h" @@ -42,7 +43,6 @@ #include "ui/views/controls/menu/submenu_view.h" #include "ui/views/widget/widget.h" #include "views/background.h" -#include "views/controls/label.h" using ui::MenuModel; using views::CustomButton; diff --git a/ui/aura_shell/examples/bubble.cc b/ui/aura_shell/examples/bubble.cc index 2bfcd6b..6eba6ba 100644 --- a/ui/aura_shell/examples/bubble.cc +++ b/ui/aura_shell/examples/bubble.cc @@ -5,9 +5,9 @@ #include "base/utf_string_conversions.h" #include "ui/views/bubble/bubble_border.h" #include "ui/views/bubble/bubble_delegate.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" namespace aura_shell { namespace examples { diff --git a/ui/views/controls/button/checkbox.cc b/ui/views/controls/button/checkbox.cc index fa79864..1221efa 100644 --- a/ui/views/controls/button/checkbox.cc +++ b/ui/views/controls/button/checkbox.cc @@ -7,7 +7,7 @@ #include "base/logging.h" #include "ui/base/accessibility/accessible_view_state.h" #include "ui/gfx/canvas.h" -#include "views/controls/label.h" +#include "ui/views/controls/label.h" namespace views { diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc new file mode 100644 index 0000000..452322e --- /dev/null +++ b/ui/views/controls/label.cc @@ -0,0 +1,503 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/controls/label.h" + +#include +#include +#include +#include + +#include "base/i18n/rtl.h" +#include "base/logging.h" +#include "base/string_split.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "ui/base/accessibility/accessible_view_state.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/text/text_elider.h" +#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/color_utils.h" +#include "ui/gfx/font.h" +#include "ui/gfx/insets.h" +#include "views/background.h" + +namespace views { + +// static +const char Label::kViewClassName[] = "views/Label"; + +const int Label::kFocusBorderPadding = 1; + +Label::Label() { + Init(string16(), GetDefaultFont()); +} + +Label::Label(const string16& text) { + Init(text, GetDefaultFont()); +} + +Label::Label(const string16& text, const gfx::Font& font) { + Init(text, font); +} + +Label::~Label() { +} + +void Label::SetFont(const gfx::Font& font) { + font_ = font; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); +} + +void Label::SetText(const string16& text) { + text_ = text; + url_set_ = false; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); +} + +const string16 Label::GetText() const { + return url_set_ ? UTF8ToUTF16(url_.spec()) : text_; +} + +void Label::SetURL(const GURL& url) { + url_ = url; + text_ = UTF8ToUTF16(url_.spec()); + url_set_ = true; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); +} + +const GURL Label::GetURL() const { + return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); +} + +void Label::SetAutoColorReadabilityEnabled(bool enabled) { + auto_color_readability_ = enabled; + RecalculateColors(); +} + +void Label::SetEnabledColor(const SkColor& color) { + requested_enabled_color_ = color; + RecalculateColors(); +} + +void Label::SetDisabledColor(const SkColor& color) { + requested_disabled_color_ = color; + RecalculateColors(); +} + +void Label::SetBackgroundColor(const SkColor& color) { + background_color_ = color; + RecalculateColors(); +} + +void Label::SetHorizontalAlignment(Alignment alignment) { + // If the View's UI layout is right-to-left and rtl_alignment_mode_ is + // USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment + // settings take into account the text directionality. + if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && + (alignment != ALIGN_CENTER)) + alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; + if (horiz_alignment_ != alignment) { + horiz_alignment_ = alignment; + SchedulePaint(); + } +} + +void Label::SetMultiLine(bool multi_line) { + DCHECK(!multi_line || !elide_in_middle_); + if (multi_line != is_multi_line_) { + is_multi_line_ = multi_line; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); + } +} + +void Label::SetAllowCharacterBreak(bool allow_character_break) { + if (allow_character_break != allow_character_break_) { + allow_character_break_ = allow_character_break; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); + } +} + +void Label::SetElideInMiddle(bool elide_in_middle) { + DCHECK(!elide_in_middle || !is_multi_line_); + if (elide_in_middle != elide_in_middle_) { + elide_in_middle_ = elide_in_middle; + text_size_valid_ = false; + PreferredSizeChanged(); + SchedulePaint(); + } +} + +void Label::SetTooltipText(const string16& tooltip_text) { + tooltip_text_ = tooltip_text; +} + +void Label::SetMouseOverBackground(Background* background) { + mouse_over_background_.reset(background); +} + +const Background* Label::GetMouseOverBackground() const { + return mouse_over_background_.get(); +} + +void Label::SizeToFit(int max_width) { + DCHECK(is_multi_line_); + + std::vector lines; + base::SplitString(text_, '\n', &lines); + + int label_width = 0; + for (std::vector::const_iterator iter = lines.begin(); + iter != lines.end(); ++iter) { + label_width = std::max(label_width, font_.GetStringWidth(*iter)); + } + + label_width += GetInsets().width(); + + if (max_width > 0) + label_width = std::min(label_width, max_width); + + SetBounds(x(), y(), label_width, 0); + SizeToPreferredSize(); +} + +void Label::SetHasFocusBorder(bool has_focus_border) { + has_focus_border_ = has_focus_border; + if (is_multi_line_) { + text_size_valid_ = false; + PreferredSizeChanged(); + } +} + +gfx::Insets Label::GetInsets() const { + gfx::Insets insets = View::GetInsets(); + if (IsFocusable() || has_focus_border_) { + insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, + kFocusBorderPadding, kFocusBorderPadding); + } + return insets; +} + +int Label::GetBaseline() const { + return GetInsets().top() + font_.GetBaseline(); +} + +gfx::Size Label::GetPreferredSize() { + // Return a size of (0, 0) if the label is not visible and if the + // collapse_when_hidden_ flag is set. + // TODO(munjal): This logic probably belongs to the View class. But for now, + // put it here since putting it in View class means all inheriting classes + // need ot respect the collapse_when_hidden_ flag. + if (!IsVisible() && collapse_when_hidden_) + return gfx::Size(); + + gfx::Size prefsize(GetTextSize()); + gfx::Insets insets = GetInsets(); + prefsize.Enlarge(insets.width(), insets.height()); + return prefsize; +} + +int Label::GetHeightForWidth(int w) { + if (!is_multi_line_) + return View::GetHeightForWidth(w); + + w = std::max(0, w - GetInsets().width()); + int h = font_.GetHeight(); + gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, + ComputeMultiLineFlags()); + return h + GetInsets().height(); +} + +std::string Label::GetClassName() const { + return kViewClassName; +} + +bool Label::HitTest(const gfx::Point& l) const { + return false; +} + +void Label::OnMouseMoved(const MouseEvent& event) { + UpdateContainsMouse(event); +} + +void Label::OnMouseEntered(const MouseEvent& event) { + UpdateContainsMouse(event); +} + +void Label::OnMouseExited(const MouseEvent& event) { + SetContainsMouse(false); +} + +bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip) const { + DCHECK(tooltip); + + // If a tooltip has been explicitly set, use it. + if (!tooltip_text_.empty()) { + tooltip->assign(tooltip_text_); + return true; + } + + // Show the full text if the text does not fit. + if (!is_multi_line_ && + (font_.GetStringWidth(text_) > GetAvailableRect().width())) { + *tooltip = text_; + return true; + } + return false; +} + +void Label::GetAccessibleState(ui::AccessibleViewState* state) { + state->role = ui::AccessibilityTypes::ROLE_STATICTEXT; + state->state = ui::AccessibilityTypes::STATE_READONLY; + state->name = text_; +} + +void Label::PaintText(gfx::Canvas* canvas, + const string16& text, + const gfx::Rect& text_bounds, + int flags) { + canvas->DrawStringInt(text, font_, + IsEnabled() ? actual_enabled_color_ : actual_disabled_color_, + text_bounds.x(), text_bounds.y(), text_bounds.width(), + text_bounds.height(), flags); + + if (HasFocus() || paint_as_focused_) { + gfx::Rect focus_bounds = text_bounds; + focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); + canvas->DrawFocusRect(focus_bounds); + } +} + +gfx::Size Label::GetTextSize() const { + if (!text_size_valid_) { + // For single-line strings, we supply the largest possible width, because + // while adding NO_ELLIPSIS to the flags works on Windows for forcing + // SizeStringInt() to calculate the desired width, it doesn't seem to work + // on Linux. + int w = is_multi_line_ ? + GetAvailableRect().width() : std::numeric_limits::max(); + int h = font_.GetHeight(); + // For single-line strings, ignore the available width and calculate how + // wide the text wants to be. + int flags = ComputeMultiLineFlags(); + if (!is_multi_line_) + flags |= gfx::Canvas::NO_ELLIPSIS; + gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); + text_size_.SetSize(w, h); + text_size_valid_ = true; + } + + return text_size_; +} + +void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { + text_size_valid_ &= !is_multi_line_; +} + +void Label::OnPaint(gfx::Canvas* canvas) { + OnPaintBackground(canvas); + + string16 paint_text; + gfx::Rect text_bounds; + int flags = 0; + CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + PaintText(canvas, paint_text, text_bounds, flags); +} + +void Label::OnPaintBackground(gfx::Canvas* canvas) { + const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL; + if (!bg) + bg = background(); + if (bg) + bg->Paint(canvas, this); +} + +// static +gfx::Font Label::GetDefaultFont() { + return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); +} + +void Label::Init(const string16& text, const gfx::Font& font) { + static bool initialized = false; + static SkColor kDefaultEnabledColor; + static SkColor kDefaultDisabledColor; + static SkColor kDefaultBackgroundColor; + if (!initialized) { +#if defined(OS_WIN) + kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); + kDefaultBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); +#else + // TODO(beng): source from theme provider. + kDefaultEnabledColor = SK_ColorBLACK; + kDefaultDisabledColor = SK_ColorGRAY; + kDefaultBackgroundColor = SK_ColorWHITE; +#endif + + initialized = true; + } + + contains_mouse_ = false; + font_ = font; + text_size_valid_ = false; + url_set_ = false; + requested_enabled_color_ = kDefaultEnabledColor; + requested_disabled_color_ = kDefaultDisabledColor; + background_color_ = kDefaultBackgroundColor; + auto_color_readability_ = true; + RecalculateColors(); + horiz_alignment_ = ALIGN_CENTER; + is_multi_line_ = false; + allow_character_break_ = false; + elide_in_middle_ = false; + collapse_when_hidden_ = false; + rtl_alignment_mode_ = USE_UI_ALIGNMENT; + paint_as_focused_ = false; + has_focus_border_ = false; + + SetText(text); +} + +void Label::RecalculateColors() { + actual_enabled_color_ = auto_color_readability_ ? + color_utils::GetReadableColor(requested_enabled_color_, + background_color_) : + requested_enabled_color_; + actual_disabled_color_ = auto_color_readability_ ? + color_utils::GetReadableColor(requested_disabled_color_, + background_color_) : + requested_disabled_color_; +} + +void Label::UpdateContainsMouse(const MouseEvent& event) { + SetContainsMouse(GetTextBounds().Contains(event.x(), event.y())); +} + +void Label::SetContainsMouse(bool contains_mouse) { + if (contains_mouse_ == contains_mouse) + return; + contains_mouse_ = contains_mouse; + if (GetMouseOverBackground()) + SchedulePaint(); +} + +gfx::Rect Label::GetTextBounds() const { + gfx::Rect available_rect(GetAvailableRect()); + gfx::Size text_size(GetTextSize()); + text_size.set_width(std::min(available_rect.width(), text_size.width())); + + gfx::Insets insets = GetInsets(); + gfx::Point text_origin(insets.left(), insets.top()); + switch (horiz_alignment_) { + case ALIGN_LEFT: + break; + case ALIGN_CENTER: + // We put any extra margin pixel on the left rather than the right. We + // used to do this because measurement on Windows used + // GetTextExtentPoint32(), which could report a value one too large on the + // right; we now use DrawText(), and who knows if it can also do this. + text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2, + 0); + break; + case ALIGN_RIGHT: + text_origin.set_x(available_rect.right() - text_size.width()); + break; + default: + NOTREACHED(); + break; + } + text_origin.Offset(0, + std::max(0, (available_rect.height() - text_size.height())) / 2); + return gfx::Rect(text_origin, text_size); +} + +int Label::ComputeMultiLineFlags() const { + if (!is_multi_line_) + return 0; + + int flags = gfx::Canvas::MULTI_LINE; +#if !defined(OS_WIN) + // Don't elide multiline labels on Linux. + // Todo(davemoore): Do we depend on eliding multiline text? + // Pango insists on limiting the number of lines to one if text is + // elided. You can get around this if you can pass a maximum height + // but we don't currently have that data when we call the pango code. + flags |= gfx::Canvas::NO_ELLIPSIS; +#endif + if (allow_character_break_) + flags |= gfx::Canvas::CHARACTER_BREAK; + switch (horiz_alignment_) { + case ALIGN_LEFT: + flags |= gfx::Canvas::TEXT_ALIGN_LEFT; + break; + case ALIGN_CENTER: + flags |= gfx::Canvas::TEXT_ALIGN_CENTER; + break; + case ALIGN_RIGHT: + flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; + break; + } + return flags; +} + +gfx::Rect Label::GetAvailableRect() const { + gfx::Rect bounds(gfx::Point(), size()); + gfx::Insets insets(GetInsets()); + bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); + return bounds; +} + +void Label::CalculateDrawStringParams(string16* paint_text, + gfx::Rect* text_bounds, + int* flags) const { + DCHECK(paint_text && text_bounds && flags); + + if (url_set_) { + // TODO(jungshik) : Figure out how to get 'intl.accept_languages' + // preference and use it when calling ElideUrl. + *paint_text = + ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string()); + + // An URLs is always treated as an LTR text and therefore we should + // explicitly mark it as such if the locale is RTL so that URLs containing + // Hebrew or Arabic characters are displayed correctly. + // + // Note that we don't check the View's UI layout setting in order to + // determine whether or not to insert the special Unicode formatting + // characters. We use the locale settings because an URL is always treated + // as an LTR string, even if its containing view does not use an RTL UI + // layout. + *paint_text = base::i18n::GetDisplayStringInLTRDirectionality( + *paint_text); + } else if (elide_in_middle_) { + *paint_text = ui::ElideText(text_, + font_, GetAvailableRect().width(), true); + } else { + *paint_text = text_; + } + + *text_bounds = GetTextBounds(); + *flags = ComputeMultiLineFlags(); + // If rtl_alignment_mode_ is AUTO_DETECT_ALIGNMENT (such as for text from + // webpage, not from chrome's UI), its directionality is forced to be RTL if + // it is right aligned. Otherwise, its directionality is forced to be LTR. + if (rtl_alignment_mode_ == AUTO_DETECT_ALIGNMENT) { + if (horiz_alignment_ == ALIGN_RIGHT) + *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; + else + *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; + } +} + +} // namespace views diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h new file mode 100644 index 0000000..4f0d6c2 --- /dev/null +++ b/ui/views/controls/label.h @@ -0,0 +1,289 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_VIEWS_CONTROLS_LABEL_H_ +#define UI_VIEWS_CONTROLS_LABEL_H_ +#pragma once + +#include + +#include "base/compiler_specific.h" +#include "base/gtest_prod_util.h" +#include "base/string16.h" +#include "googleurl/src/gurl.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/font.h" +#include "views/view.h" + +namespace views { + +///////////////////////////////////////////////////////////////////////////// +// +// Label class +// +// A label is a view subclass that can display a string. +// +///////////////////////////////////////////////////////////////////////////// +class VIEWS_EXPORT Label : public View { + public: + enum Alignment { ALIGN_LEFT = 0, + ALIGN_CENTER, + ALIGN_RIGHT }; + + // The following enum is used to indicate whether using the Chrome UI's + // alignment as the label's alignment, or autodetecting the label's + // alignment. + // + // If the label text originates from the Chrome UI, we should use the Chrome + // UI's alignment as the label's alignment. + // + // If the text originates from a web page, the text's alignment is determined + // based on the first character with strong directionality, disregarding what + // directionality the Chrome UI is. And its alignment will not be flipped + // around in RTL locales. + enum RTLAlignmentMode { + USE_UI_ALIGNMENT = 0, + AUTO_DETECT_ALIGNMENT + }; + + // The view class name. + static const char kViewClassName[]; + + // The padding for the focus border when rendering focused text. + static const int kFocusBorderPadding; + + Label(); + explicit Label(const string16& text); + Label(const string16& text, const gfx::Font& font); + virtual ~Label(); + + // Set the font. + virtual void SetFont(const gfx::Font& font); + + // Set the label text. + void SetText(const string16& text); + + // Return the font used by this label. + gfx::Font font() const { return font_; } + + // Return the label text. + const string16 GetText() const; + + // Set URL Value - text_ is set to spec(). + void SetURL(const GURL& url); + + // Return the label URL. + const GURL GetURL() const; + + // Enables or disables auto-color-readability (enabled by default). If this + // is enabled, then calls to set any foreground or background color will + // trigger an automatic mapper that uses color_utils::GetReadableColor() to + // ensure that the foreground colors are readable over the background color. + void SetAutoColorReadabilityEnabled(bool enabled); + + // Set the color. This will automatically force the color to be readable + // over the current background color. + virtual void SetEnabledColor(const SkColor& color); + void SetDisabledColor(const SkColor& color); + + SkColor enabled_color() const { return actual_enabled_color_; } + + // Set the background color. This won't be explicitly drawn, but the label + // will force the text color to be readable over it. + void SetBackgroundColor(const SkColor& color); + + // Set horizontal alignment. If the locale is RTL, and the RTL alignment + // setting is set as USE_UI_ALIGNMENT, the alignment is flipped around. + // + // Caveat: for labels originating from a web page, the RTL alignment mode + // should be reset to AUTO_DETECT_ALIGNMENT before the horizontal alignment + // is set. Otherwise, the label's alignment specified as a parameter will be + // flipped in RTL locales. Please see the comments in SetRTLAlignmentMode for + // more information. + void SetHorizontalAlignment(Alignment alignment); + + Alignment horizontal_alignment() const { return horiz_alignment_; } + + // Set the RTL alignment mode. The RTL alignment mode is initialized to + // USE_UI_ALIGNMENT when the label is constructed. USE_UI_ALIGNMENT applies + // to every label that originates from the Chrome UI. However, if the label + // originates from a web page, its alignment should not be flipped around for + // RTL locales. For such labels, we need to set the RTL alignment mode to + // AUTO_DETECT_ALIGNMENT so that subsequent SetHorizontalAlignment() calls + // will not flip the label's alignment around. + void set_rtl_alignment_mode(RTLAlignmentMode mode) { + rtl_alignment_mode_ = mode; + } + RTLAlignmentMode rtl_alignment_mode() const { return rtl_alignment_mode_; } + + // Set whether the label text can wrap on multiple lines. + // Default is false. + void SetMultiLine(bool multi_line); + + // Return whether the label text can wrap on multiple lines. + bool is_multi_line() const { return is_multi_line_; } + + // Set whether the label text can be split on words. + // Default is false. This only works when is_multi_line is true. + void SetAllowCharacterBreak(bool allow_character_break); + + // Set whether the label text should be elided in the middle (if necessary). + // The default is to elide at the end. + // NOTE: This is not supported for multi-line strings. + void SetElideInMiddle(bool elide_in_middle); + + // Sets the tooltip text. Default behavior for a label (single-line) is to + // show the full text if it is wider than its bounds. Calling this overrides + // the default behavior and lets you set a custom tooltip. To revert to + // default behavior, call this with an empty string. + void SetTooltipText(const string16& tooltip_text); + + // The background color to use when the mouse is over the label. Label + // takes ownership of the Background. + void SetMouseOverBackground(Background* background); + const Background* GetMouseOverBackground() const; + + // Resizes the label so its width is set to the width of the longest line and + // its height deduced accordingly. + // This is only intended for multi-line labels and is useful when the label's + // text contains several lines separated with \n. + // |max_width| is the maximum width that will be used (longer lines will be + // wrapped). If 0, no maximum width is enforced. + void SizeToFit(int max_width); + + // Gets/sets the flag to determine whether the label should be collapsed when + // it's hidden (not visible). If this flag is true, the label will return a + // preferred size of (0, 0) when it's not visible. + void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; } + bool collapse_when_hidden() const { return collapse_when_hidden_; } + + // Gets/set whether or not this label is to be painted as a focused element. + void set_paint_as_focused(bool paint_as_focused) { + paint_as_focused_ = paint_as_focused; + } + bool paint_as_focused() const { return paint_as_focused_; } + + void SetHasFocusBorder(bool has_focus_border); + + // Overridden from View: + virtual gfx::Insets GetInsets() const OVERRIDE; + virtual int GetBaseline() const OVERRIDE; + // Overridden to compute the size required to display this label. + virtual gfx::Size GetPreferredSize() OVERRIDE; + // Return the height necessary to display this label with the provided width. + // This method is used to layout multi-line labels. It is equivalent to + // GetPreferredSize().height() if the receiver is not multi-line. + virtual int GetHeightForWidth(int w) OVERRIDE; + virtual std::string GetClassName() const OVERRIDE; + virtual bool HitTest(const gfx::Point& l) const OVERRIDE; + // Mouse enter/exit are overridden to render mouse over background color. + // These invoke SetContainsMouse as necessary. + virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; + virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; + virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; + // Gets the tooltip text for labels that are wider than their bounds, except + // when the label is multiline, in which case it just returns false (no + // tooltip). If a custom tooltip has been specified with SetTooltipText() + // it is returned instead. + virtual bool GetTooltipText(const gfx::Point& p, + string16* tooltip) const OVERRIDE; + + protected: + // Called by Paint to paint the text. Override this to change how + // text is painted. + virtual void PaintText(gfx::Canvas* canvas, + const string16& text, + const gfx::Rect& text_bounds, + int flags); + + void invalidate_text_size() { text_size_valid_ = false; } + + virtual gfx::Size GetTextSize() const; + + SkColor disabled_color() const { return actual_disabled_color_; } + + // Overridden from View: + // Overridden to dirty our text bounds if we're multi-line. + virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + // If the mouse is over the label, and a mouse over background has been + // specified, its used. Otherwise super's implementation is invoked. + virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; + + private: + // These tests call CalculateDrawStringParams in order to verify the + // calculations done for drawing text. + FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); + FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); + FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); + FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); + + static gfx::Font GetDefaultFont(); + + void Init(const string16& text, const gfx::Font& font); + + void RecalculateColors(); + + // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise + // SetContainsMouse(false) is invoked. + void UpdateContainsMouse(const MouseEvent& event); + + // Updates whether the mouse is contained in the Label. If the new value + // differs from the current value, and a mouse over background is specified, + // SchedulePaint is invoked. + void SetContainsMouse(bool contains_mouse); + + // Returns where the text is drawn, in the receivers coordinate system. + gfx::Rect GetTextBounds() const; + + int ComputeMultiLineFlags() const; + + gfx::Rect GetAvailableRect() const; + + // Returns parameters to be used for the DrawString call. + void CalculateDrawStringParams(string16* paint_text, + gfx::Rect* text_bounds, + int* flags) const; + + string16 text_; + GURL url_; + gfx::Font font_; + SkColor requested_enabled_color_; + SkColor actual_enabled_color_; + SkColor requested_disabled_color_; + SkColor actual_disabled_color_; + SkColor background_color_; + bool auto_color_readability_; + mutable gfx::Size text_size_; + mutable bool text_size_valid_; + bool is_multi_line_; + bool allow_character_break_; + bool elide_in_middle_; + bool url_set_; + Alignment horiz_alignment_; + string16 tooltip_text_; + // Whether the mouse is over this label. + bool contains_mouse_; + scoped_ptr mouse_over_background_; + // Whether to collapse the label when it's not visible. + bool collapse_when_hidden_; + // The following member variable is used to control whether the alignment + // needs to be flipped around for RTL locales. Please refer to the definition + // of RTLAlignmentMode for more information. + RTLAlignmentMode rtl_alignment_mode_; + // When embedded in a larger control that is focusable, setting this flag + // allows this view to be painted as focused even when it is itself not. + bool paint_as_focused_; + // When embedded in a larger control that is focusable, setting this flag + // allows this view to reserve space for a focus border that it otherwise + // might not have because it is not itself focusable. + bool has_focus_border_; + + DISALLOW_COPY_AND_ASSIGN(Label); +}; + +} // namespace views + +#endif // UI_VIEWS_CONTROLS_LABEL_H_ diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc new file mode 100644 index 0000000..426614b --- /dev/null +++ b/ui/views/controls/label_unittest.cc @@ -0,0 +1,811 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/i18n/rtl.h" +#include "base/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/accessibility/accessible_view_state.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/canvas.h" +#include "ui/views/controls/label.h" +#include "views/border.h" + +namespace views { + +// All text sizing measurements (width and height) should be greater than this. +const int kMinTextDimension = 4; + +#if defined(OS_WIN) +// Courier is failing on linux because it's non scalable. +TEST(LabelTest, FontPropertyCourier) { + Label label; + std::string font_name("courier"); + gfx::Font font(font_name, 30); + label.SetFont(font); + gfx::Font font_used = label.font(); + EXPECT_EQ(font_name, font_used.GetFontName()); + EXPECT_EQ(30, font_used.GetFontSize()); +} +#endif + +TEST(LabelTest, FontPropertyArial) { + Label label; + std::string font_name("arial"); + gfx::Font font(font_name, 30); + label.SetFont(font); + gfx::Font font_used = label.font(); + EXPECT_EQ(font_name, font_used.GetFontName()); + EXPECT_EQ(30, font_used.GetFontSize()); +} + +TEST(LabelTest, TextProperty) { + Label label; + string16 test_text(ASCIIToUTF16("A random string.")); + label.SetText(test_text); + EXPECT_EQ(test_text, label.GetText()); +} + +TEST(LabelTest, UrlProperty) { + Label label; + std::string my_url("http://www.orkut.com/some/Random/path"); + GURL url(my_url); + label.SetURL(url); + EXPECT_EQ(my_url, label.GetURL().spec()); + EXPECT_EQ(UTF8ToUTF16(my_url), label.GetText()); +} + +TEST(LabelTest, ColorProperty) { + Label label; + SkColor color = SkColorSetARGB(20, 40, 10, 5); + label.SetAutoColorReadabilityEnabled(false); + label.SetEnabledColor(color); + EXPECT_EQ(color, label.enabled_color()); +} + +TEST(LabelTest, AlignmentProperty) { + Label label; + bool reverse_alignment = base::i18n::IsRTL(); + + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + EXPECT_EQ( + reverse_alignment ? Label::ALIGN_LEFT : Label::ALIGN_RIGHT, + label.horizontal_alignment()); + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + EXPECT_EQ( + reverse_alignment ? Label::ALIGN_RIGHT : Label::ALIGN_LEFT, + label.horizontal_alignment()); + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); + + // The label's alignment should not be flipped if the RTL alignment mode + // is AUTO_DETECT_ALIGNMENT. + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + EXPECT_EQ(Label::ALIGN_RIGHT, label.horizontal_alignment()); + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + EXPECT_EQ(Label::ALIGN_LEFT, label.horizontal_alignment()); + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); +} + +TEST(LabelTest, RTLAlignmentModeProperty) { + Label label; + EXPECT_EQ(Label::USE_UI_ALIGNMENT, label.rtl_alignment_mode()); + + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); + EXPECT_EQ(Label::AUTO_DETECT_ALIGNMENT, label.rtl_alignment_mode()); + + label.set_rtl_alignment_mode(Label::USE_UI_ALIGNMENT); + EXPECT_EQ(Label::USE_UI_ALIGNMENT, label.rtl_alignment_mode()); +} + +TEST(LabelTest, MultiLineProperty) { + Label label; + EXPECT_FALSE(label.is_multi_line()); + label.SetMultiLine(true); + EXPECT_TRUE(label.is_multi_line()); + label.SetMultiLine(false); + EXPECT_FALSE(label.is_multi_line()); +} + +TEST(LabelTest, TooltipProperty) { + Label label; + string16 test_text(ASCIIToUTF16("My cool string.")); + label.SetText(test_text); + + string16 tooltip; + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + EXPECT_EQ(test_text, tooltip); + + string16 tooltip_text(ASCIIToUTF16("The tooltip!")); + label.SetTooltipText(tooltip_text); + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + EXPECT_EQ(tooltip_text, tooltip); + + string16 empty_text; + label.SetTooltipText(empty_text); + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + EXPECT_EQ(test_text, tooltip); + + // Make the label big enough to hold the text + // and expect there to be no tooltip. + label.SetBounds(0, 0, 1000, 40); + EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); + + // Verify that setting the tooltip still shows it. + label.SetTooltipText(tooltip_text); + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + EXPECT_EQ(tooltip_text, tooltip); + // Clear out the tooltip. + label.SetTooltipText(empty_text); + + // Shrink the bounds and the tooltip should come back. + label.SetBounds(0, 0, 1, 1); + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + + // Make the label multiline and there is no tooltip again. + label.SetMultiLine(true); + EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); + + // Verify that setting the tooltip still shows it. + label.SetTooltipText(tooltip_text); + EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); + EXPECT_EQ(tooltip_text, tooltip); + // Clear out the tooltip. + label.SetTooltipText(empty_text); +} + +TEST(LabelTest, Accessibility) { + Label label; + string16 test_text(ASCIIToUTF16("My special text.")); + label.SetText(test_text); + + ui::AccessibleViewState state; + label.GetAccessibleState(&state); + EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); + EXPECT_EQ(test_text, state.name); + EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); +} + +TEST(LabelTest, SingleLineSizing) { + Label label; + string16 test_text(ASCIIToUTF16("A not so random string in one line.")); + label.SetText(test_text); + + // GetPreferredSize + gfx::Size required_size = label.GetPreferredSize(); + EXPECT_GT(required_size.height(), kMinTextDimension); + EXPECT_GT(required_size.width(), kMinTextDimension); + + // Test everything with borders. + gfx::Insets border(10, 20, 30, 40); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + + // GetPreferredSize and borders. + label.SetBounds(0, 0, 0, 0); + gfx::Size required_size_with_border = label.GetPreferredSize(); + EXPECT_EQ(required_size_with_border.height(), + required_size.height() + border.height()); + EXPECT_EQ(required_size_with_border.width(), + required_size.width() + border.width()); +} + +TEST(LabelTest, MultiLineSizing) { + Label label; + label.set_focusable(false); + string16 test_text( + ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); + label.SetText(test_text); + label.SetMultiLine(true); + + // GetPreferredSize + gfx::Size required_size = label.GetPreferredSize(); + EXPECT_GT(required_size.height(), kMinTextDimension); + EXPECT_GT(required_size.width(), kMinTextDimension); + + // SizeToFit with unlimited width. + label.SizeToFit(0); + int required_width = label.GetLocalBounds().width(); + EXPECT_GT(required_width, kMinTextDimension); + + // SizeToFit with limited width. + label.SizeToFit(required_width - 1); + int constrained_width = label.GetLocalBounds().width(); +#if defined(OS_WIN) + // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) + // has to be fixed to return the size that fits to given width/height. + EXPECT_LT(constrained_width, required_width); +#endif + EXPECT_GT(constrained_width, kMinTextDimension); + + // Change the width back to the desire width. + label.SizeToFit(required_width); + EXPECT_EQ(required_width, label.GetLocalBounds().width()); + + // General tests for GetHeightForWidth. + int required_height = label.GetHeightForWidth(required_width); + EXPECT_GT(required_height, kMinTextDimension); + int height_for_constrained_width = label.GetHeightForWidth(constrained_width); +#if defined(OS_WIN) + // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) + // has to be fixed to return the size that fits to given width/height. + EXPECT_GT(height_for_constrained_width, required_height); +#endif + // Using the constrained width or the required_width - 1 should give the + // same result for the height because the constrainted width is the tight + // width when given "required_width - 1" as the max width. + EXPECT_EQ(height_for_constrained_width, + label.GetHeightForWidth(required_width - 1)); + + // Test everything with borders. + gfx::Insets border(10, 20, 30, 40); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + + // SizeToFit and borders. + label.SizeToFit(0); + int required_width_with_border = label.GetLocalBounds().width(); + EXPECT_EQ(required_width_with_border, required_width + border.width()); + + // GetHeightForWidth and borders. + int required_height_with_border = + label.GetHeightForWidth(required_width_with_border); + EXPECT_EQ(required_height_with_border, required_height + border.height()); + + // Test that the border width is subtracted before doing the height + // calculation. If it is, then the height will grow when width + // is shrunk. + int height1 = label.GetHeightForWidth(required_width_with_border - 1); +#if defined(OS_WIN) + // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) + // has to be fixed to return the size that fits to given width/height. + EXPECT_GT(height1, required_height_with_border); +#endif + EXPECT_EQ(height1, height_for_constrained_width + border.height()); + + // GetPreferredSize and borders. + label.SetBounds(0, 0, 0, 0); + gfx::Size required_size_with_border = label.GetPreferredSize(); + EXPECT_EQ(required_size_with_border.height(), + required_size.height() + border.height()); + EXPECT_EQ(required_size_with_border.width(), + required_size.width() + border.width()); +} + +TEST(LabelTest, DrawSingleLineString) { + Label label; + label.set_focusable(false); + + // Turn off mirroring so that we don't need to figure out if + // align right really means align left. + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); + + string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); + label.SetText(test_text); + gfx::Size required_size(label.GetPreferredSize()); + gfx::Size extra(22, 8); + label.SetBounds(0, + 0, + required_size.width() + extra.width(), + required_size.height() + extra.height()); + + // Do some basic verifications for all three alignments. + string16 paint_text; + gfx::Rect text_bounds; + int flags; + + // Centered text. + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be centered horizontally and vertically. + EXPECT_EQ(extra.width() / 2, text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); + + // Left aligned text. + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be left aligned horizontally and centered vertically. + EXPECT_EQ(0, text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); + + // Right aligned text. + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be right aligned horizontally and centered vertically. + EXPECT_EQ(extra.width(), text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); + + // Test single line drawing with a border. + gfx::Insets border(39, 34, 8, 96); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + + gfx::Size required_size_with_border(label.GetPreferredSize()); + EXPECT_EQ(required_size.width() + border.width(), + required_size_with_border.width()); + EXPECT_EQ(required_size.height() + border.height(), + required_size_with_border.height()); + label.SetBounds(0, + 0, + required_size_with_border.width() + extra.width(), + required_size_with_border.height() + extra.height()); + + // Centered text with border. + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be centered horizontally and vertically within the border. + EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); + + // Left aligned text with border. + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be left aligned horizontally and centered vertically. + EXPECT_EQ(border.left(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); + + // Right aligned text. + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be right aligned horizontally and centered vertically. + EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); +} + +// On Linux the underlying pango routines require a max height in order to +// ellide multiline text. So until that can be resolved, we set all +// multiline lables to not ellide in Linux only. +TEST(LabelTest, DrawMultiLineString) { + Label label; + label.set_focusable(false); + + // Turn off mirroring so that we don't need to figure out if + // align right really means align left. + label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); + + string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); + label.SetText(test_text); + label.SetMultiLine(true); + label.SizeToFit(0); + gfx::Size extra(50, 10); + label.SetBounds(label.x(), + label.y(), + label.width() + extra.width(), + label.height() + extra.height()); + + // Do some basic verifications for all three alignments. + string16 paint_text; + gfx::Rect text_bounds; + int flags; + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(extra.width() / 2, text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); + int expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif + gfx::Rect center_bounds(text_bounds); + + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(0, text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(extra.width(), text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::FORCE_RTL_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif + + // Test multiline drawing with a border. + gfx::Insets border(19, 92, 23, 2); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + label.SizeToFit(0); + label.SetBounds(label.x(), + label.y(), + label.width() + extra.width(), + label.height() + extra.height()); + + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(border.left(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::FORCE_LTR_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(extra.width() + border.left(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); + expected_flags = gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::FORCE_RTL_DIRECTIONALITY; +#if defined(OS_WIN) + EXPECT_EQ(expected_flags, flags); +#else + EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); +#endif +} + +TEST(LabelTest, DrawSingleLineStringInRTL) { + Label label; + label.set_focusable(false); + + std::string locale = l10n_util::GetApplicationLocale(""); + base::i18n::SetICUDefaultLocale("he"); + + string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); + label.SetText(test_text); + gfx::Size required_size(label.GetPreferredSize()); + gfx::Size extra(22, 8); + label.SetBounds(0, + 0, + required_size.width() + extra.width(), + required_size.height() + extra.height()); + + // Do some basic verifications for all three alignments. + string16 paint_text; + gfx::Rect text_bounds; + int flags; + + // Centered text. + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be centered horizontally and vertically. + EXPECT_EQ(extra.width() / 2, text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + // ALIGN_LEFT label. + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be right aligned horizontally and centered vertically. + EXPECT_EQ(extra.width(), text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + // ALIGN_RIGHT label. + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be left aligned horizontally and centered vertically. + EXPECT_EQ(0, text_bounds.x()); + EXPECT_EQ(extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + + // Test single line drawing with a border. + gfx::Insets border(39, 34, 8, 96); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + + gfx::Size required_size_with_border(label.GetPreferredSize()); + EXPECT_EQ(required_size.width() + border.width(), + required_size_with_border.width()); + EXPECT_EQ(required_size.height() + border.height(), + required_size_with_border.height()); + label.SetBounds(0, + 0, + required_size_with_border.width() + extra.width(), + required_size_with_border.height() + extra.height()); + + // Centered text with border. + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be centered horizontally and vertically within the border. + EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + // ALIGN_LEFT text with border. + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be right aligned horizontally and centered vertically. + EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + // ALIGN_RIGHT text. + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + // The text should be left aligned horizontally and centered vertically. + EXPECT_EQ(border.left(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); + EXPECT_EQ(required_size.width(), text_bounds.width()); + EXPECT_EQ(required_size.height(), text_bounds.height()); + EXPECT_EQ(0, flags); + + // Reset locale. + base::i18n::SetICUDefaultLocale(locale); +} + +// On Linux the underlying pango routines require a max height in order to +// ellide multiline text. So until that can be resolved, we set all +// multiline lables to not ellide in Linux only. +TEST(LabelTest, DrawMultiLineStringInRTL) { + Label label; + label.set_focusable(false); + + // Test for RTL. + std::string locale = l10n_util::GetApplicationLocale(""); + base::i18n::SetICUDefaultLocale("he"); + + string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); + label.SetText(test_text); + label.SetMultiLine(true); + label.SizeToFit(0); + gfx::Size extra(50, 10); + label.SetBounds(label.x(), + label.y(), + label.width() + extra.width(), + label.height() + extra.height()); + + // Do some basic verifications for all three alignments. + string16 paint_text; + gfx::Rect text_bounds; + int flags; + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(extra.width() / 2, text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + gfx::Rect center_bounds(text_bounds); + + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(extra.width(), text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(0, text_bounds.x()); + EXPECT_EQ(extra.height() / 2, text_bounds.y()); + EXPECT_GT(text_bounds.width(), kMinTextDimension); + EXPECT_GT(text_bounds.height(), kMinTextDimension); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + + // Test multiline drawing with a border. + gfx::Insets border(19, 92, 23, 2); + label.set_border(Border::CreateEmptyBorder(border.top(), + border.left(), + border.bottom(), + border.right())); + label.SizeToFit(0); + label.SetBounds(label.x(), + label.y(), + label.width() + extra.width(), + label.height() + extra.height()); + + label.SetHorizontalAlignment(Label::ALIGN_CENTER); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_CENTER | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_LEFT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_RIGHT | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + + label.SetHorizontalAlignment(Label::ALIGN_RIGHT); + paint_text.clear(); + text_bounds.SetRect(0, 0, 0, 0); + label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); + EXPECT_EQ(test_text, paint_text); + EXPECT_EQ(border.left(), text_bounds.x()); + EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); + EXPECT_EQ(center_bounds.width(), text_bounds.width()); + EXPECT_EQ(center_bounds.height(), text_bounds.height()); +#if defined(OS_WIN) + EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); +#else + EXPECT_EQ( + gfx::Canvas::MULTI_LINE | + gfx::Canvas::TEXT_ALIGN_LEFT | + gfx::Canvas::NO_ELLIPSIS, + flags); +#endif + + // Reset Locale + base::i18n::SetICUDefaultLocale(locale); +} + +} // namespace views diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc new file mode 100644 index 0000000..16da0c3 --- /dev/null +++ b/ui/views/controls/link.cc @@ -0,0 +1,200 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/views/controls/link.h" + +#include "build/build_config.h" + +#if defined(TOOLKIT_USES_GTK) +#include +#endif + +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "ui/base/accessibility/accessible_view_state.h" +#include "ui/base/keycodes/keyboard_codes.h" +#include "ui/gfx/color_utils.h" +#include "ui/gfx/font.h" +#include "ui/views/controls/link_listener.h" +#include "ui/views/events/event.h" + +#if defined(TOOLKIT_USES_GTK) +#include "ui/gfx/gtk_util.h" +#endif + +#if defined(USE_AURA) +#include "ui/aura/cursor.h" +#endif + +namespace views { + +const char Link::kViewClassName[] = "views/Link"; + +Link::Link() : Label(string16()) { + Init(); +} + +Link::Link(const string16& title) : Label(title) { + Init(); +} + +Link::~Link() { +} + +void Link::OnEnabledChanged() { + RecalculateFont(); + View::OnEnabledChanged(); +} + +std::string Link::GetClassName() const { + return kViewClassName; +} + +gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { + if (!IsEnabled()) + return gfx::kNullCursor; +#if defined(USE_AURA) + return aura::kCursorHand; +#elif defined(OS_WIN) + static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); + return g_hand_cursor; +#elif defined(TOOLKIT_USES_GTK) + return gfx::GetCursor(GDK_HAND2); +#endif +} + +bool Link::HitTest(const gfx::Point& l) const { + // We need to allow clicks on the link. So we override the implementation in + // Label and use the default implementation of View. + return View::HitTest(l); +} + +bool Link::OnMousePressed(const MouseEvent& event) { + if (!IsEnabled() || + (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) + return false; + SetPressed(true); + return true; +} + +bool Link::OnMouseDragged(const MouseEvent& event) { + SetPressed(IsEnabled() && + (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && + HitTest(event.location())); + return true; +} + +void Link::OnMouseReleased(const MouseEvent& event) { + // Change the highlight first just in case this instance is deleted + // while calling the controller + OnMouseCaptureLost(); + if (IsEnabled() && + (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && + HitTest(event.location())) { + // Focus the link on click. + RequestFocus(); + + if (listener_) + listener_->LinkClicked(this, event.flags()); + } +} + +void Link::OnMouseCaptureLost() { + SetPressed(false); +} + +bool Link::OnKeyPressed(const KeyEvent& event) { + bool activate = ((event.key_code() == ui::VKEY_SPACE) || + (event.key_code() == ui::VKEY_RETURN)); + if (!activate) + return false; + + SetPressed(false); + + // Focus the link on key pressed. + RequestFocus(); + + if (listener_) + listener_->LinkClicked(this, event.flags()); + + return true; +} + +bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& event) { + // Make sure we don't process space or enter as accelerators. + return (event.key_code() == ui::VKEY_SPACE) || + (event.key_code() == ui::VKEY_RETURN); +} + +void Link::GetAccessibleState(ui::AccessibleViewState* state) { + Label::GetAccessibleState(state); + state->role = ui::AccessibilityTypes::ROLE_LINK; +} + +void Link::SetFont(const gfx::Font& font) { + Label::SetFont(font); + RecalculateFont(); +} + +void Link::SetEnabledColor(const SkColor& color) { + requested_enabled_color_ = color; + if (!pressed_) + Label::SetEnabledColor(requested_enabled_color_); +} + +void Link::SetPressedColor(const SkColor& color) { + requested_pressed_color_ = color; + if (pressed_) + Label::SetEnabledColor(requested_pressed_color_); +} + +void Link::Init() { + static bool initialized = false; + static SkColor kDefaultEnabledColor; + static SkColor kDefaultDisabledColor; + static SkColor kDefaultPressedColor; + if (!initialized) { +#if defined(OS_WIN) + kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); + kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kDefaultPressedColor = SkColorSetRGB(200, 0, 0); +#else + // TODO(beng): source from theme provider. + kDefaultEnabledColor = SkColorSetRGB(0, 51, 153); + kDefaultDisabledColor = SK_ColorBLACK; + kDefaultPressedColor = SK_ColorRED; +#endif + + initialized = true; + } + + listener_ = NULL; + pressed_ = false; + SetEnabledColor(kDefaultEnabledColor); + SetDisabledColor(kDefaultDisabledColor); + SetPressedColor(kDefaultPressedColor); + RecalculateFont(); + set_focusable(true); +} + +void Link::SetPressed(bool pressed) { + if (pressed_ != pressed) { + pressed_ = pressed; + Label::SetEnabledColor(pressed_ ? + requested_pressed_color_ : requested_enabled_color_); + RecalculateFont(); + SchedulePaint(); + } +} + +void Link::RecalculateFont() { + // The font should be underlined iff the link is enabled. + if (IsEnabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { + Label::SetFont(font().DeriveFont(0, IsEnabled() ? + (font().GetStyle() | gfx::Font::UNDERLINED) : + (font().GetStyle() & ~gfx::Font::UNDERLINED))); + } +} + +} // namespace views diff --git a/ui/views/controls/link.h b/ui/views/controls/link.h new file mode 100644 index 0000000..2850516 --- /dev/null +++ b/ui/views/controls/link.h @@ -0,0 +1,78 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_VIEWS_CONTROLS_LINK_H_ +#define UI_VIEWS_CONTROLS_LINK_H_ +#pragma once + +#include + +#include "ui/views/controls/label.h" + +namespace views { + +class LinkListener; + +//////////////////////////////////////////////////////////////////////////////// +// +// Link class +// +// A Link is a label subclass that looks like an HTML link. It has a +// controller which is notified when a click occurs. +// +//////////////////////////////////////////////////////////////////////////////// +class VIEWS_EXPORT Link : public Label { + public: + Link(); + explicit Link(const string16& title); + virtual ~Link(); + + const LinkListener* listener() { return listener_; } + void set_listener(LinkListener* listener) { listener_ = listener; } + + // Overridden from View: + virtual void OnEnabledChanged() OVERRIDE; + virtual std::string GetClassName() const OVERRIDE; + virtual gfx::NativeCursor GetCursor(const MouseEvent& event) OVERRIDE; + virtual bool HitTest(const gfx::Point& l) const OVERRIDE; + virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; + virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; + virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; + virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) OVERRIDE; + virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; + + // Overridden from Label: + virtual void SetFont(const gfx::Font& font) OVERRIDE; + + virtual void SetEnabledColor(const SkColor& color) OVERRIDE; + void SetPressedColor(const SkColor& color); + + static const char kViewClassName[]; + + private: + void Init(); + + void SetPressed(bool pressed); + + void RecalculateFont(); + + LinkListener* listener_; + + // Whether the link is currently pressed. + bool pressed_; + + // The color when the link is neither pressed nor disabled. + SkColor requested_enabled_color_; + + // The color when the link is pressed. + SkColor requested_pressed_color_; + + DISALLOW_COPY_AND_ASSIGN(Link); +}; + +} // namespace views + +#endif // UI_VIEWS_CONTROLS_LINK_H_ diff --git a/ui/views/controls/link_listener.h b/ui/views/controls/link_listener.h new file mode 100644 index 0000000..3ae3475 --- /dev/null +++ b/ui/views/controls/link_listener.h @@ -0,0 +1,24 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_VIEWS_CONTROLS_LINK_LISTENER_H_ +#define UI_VIEWS_CONTROLS_LINK_LISTENER_H_ +#pragma once + +namespace views { + +class Link; + +// An interface implemented by an object to let it know that a link was clicked. +class LinkListener { + public: + virtual void LinkClicked(Link* source, int event_flags) = 0; + + protected: + virtual ~LinkListener() {} +}; + +} // namespace views + +#endif // UI_VIEWS_CONTROLS_LINK_LISTENER_H_ diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc index bbbdbd4..20cae12 100644 --- a/ui/views/controls/textfield/native_textfield_win.cc +++ b/ui/views/controls/textfield/native_textfield_win.cc @@ -23,6 +23,7 @@ #include "ui/base/range/range.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/gfx/native_theme_win.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_2.h" #include "ui/views/controls/menu/menu_win.h" #include "ui/views/controls/native/native_view_host.h" @@ -31,7 +32,6 @@ #include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/focus/focus_manager.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #include "views/metrics.h" #include "views/views_delegate.h" diff --git a/ui/views/examples/bubble_example.cc b/ui/views/examples/bubble_example.cc index 2341447..f2409e4 100644 --- a/ui/views/examples/bubble_example.cc +++ b/ui/views/examples/bubble_example.cc @@ -7,10 +7,10 @@ #include "base/utf_string_conversions.h" #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/layout/box_layout.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" namespace examples { diff --git a/ui/views/examples/examples_main.cc b/ui/views/examples/examples_main.cc index 1c874b3..1429140 100644 --- a/ui/views/examples/examples_main.cc +++ b/ui/views/examples/examples_main.cc @@ -13,6 +13,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/tabbed_pane/tabbed_pane.h" #include "ui/views/examples/bubble_example.h" #include "ui/views/examples/button_example.h" @@ -37,7 +38,6 @@ #include "ui/views/layout/grid_layout.h" #include "ui/views/test/test_views_delegate.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" #if defined(OS_WIN) // TableView is not yet ported to Linux. diff --git a/ui/views/examples/link_example.cc b/ui/views/examples/link_example.cc index 69731ad..e1482ff 100644 --- a/ui/views/examples/link_example.cc +++ b/ui/views/examples/link_example.cc @@ -5,8 +5,8 @@ #include "ui/views/examples/link_example.h" #include "base/utf_string_conversions.h" +#include "ui/views/controls/link.h" #include "ui/views/layout/fill_layout.h" -#include "views/controls/link.h" #include "views/view.h" namespace examples { diff --git a/ui/views/examples/link_example.h b/ui/views/examples/link_example.h index 38513f6..f2d89c3 100644 --- a/ui/views/examples/link_example.h +++ b/ui/views/examples/link_example.h @@ -8,8 +8,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ui/views/controls/link_listener.h" #include "ui/views/examples/example_base.h" -#include "views/controls/link_listener.h" namespace views { class View; diff --git a/ui/views/examples/native_theme_button_example.cc b/ui/views/examples/native_theme_button_example.cc index ded8483..5f06143 100644 --- a/ui/views/examples/native_theme_button_example.cc +++ b/ui/views/examples/native_theme_button_example.cc @@ -13,9 +13,9 @@ #include "ui/base/models/combobox_model.h" #include "ui/gfx/canvas.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/examples/example_combobox_model.h" #include "ui/views/layout/grid_layout.h" -#include "views/controls/label.h" #include "views/native_theme_painter.h" namespace { diff --git a/ui/views/examples/text_example.cc b/ui/views/examples/text_example.cc index a73bbe1..45cc134 100644 --- a/ui/views/examples/text_example.cc +++ b/ui/views/examples/text_example.cc @@ -10,9 +10,9 @@ #include "ui/gfx/canvas_skia.h" #include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" #include "ui/views/examples/example_combobox_model.h" #include "ui/views/layout/grid_layout.h" -#include "views/controls/label.h" #include "views/view.h" namespace { diff --git a/ui/views/examples/textfield_example.cc b/ui/views/examples/textfield_example.cc index 3a9a7d6..ee1fa15 100644 --- a/ui/views/examples/textfield_example.cc +++ b/ui/views/examples/textfield_example.cc @@ -7,9 +7,9 @@ #include "base/utf_string_conversions.h" #include "ui/base/range/range.h" #include "ui/gfx/render_text.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" -#include "views/controls/label.h" #include "views/view.h" namespace examples { diff --git a/ui/views/focus/focus_traversal_unittest.cc b/ui/views/focus/focus_traversal_unittest.cc index 3e9127b..3605015 100644 --- a/ui/views/focus/focus_traversal_unittest.cc +++ b/ui/views/focus/focus_traversal_unittest.cc @@ -11,13 +11,13 @@ #include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/controls/combobox/combobox.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/focus/focus_manager_test.h" #include "ui/views/widget/root_view.h" #include "ui/views/widget/widget.h" -#include "views/controls/label.h" -#include "views/controls/link.h" #include "views/controls/scroll_view.h" #if !defined(USE_AURA) diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc index 1d64a0a..894c8a4 100644 --- a/ui/views/touchui/touch_selection_controller_impl.cc +++ b/ui/views/touchui/touch_selection_controller_impl.cc @@ -20,11 +20,11 @@ #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_config.h" #include "ui/views/layout/box_layout.h" #include "ui/views/widget/widget.h" #include "views/background.h" -#include "views/controls/label.h" namespace { diff --git a/ui/views/widget/tooltip_manager_views.h b/ui/views/widget/tooltip_manager_views.h index 29d7048..e844ddf 100644 --- a/ui/views/widget/tooltip_manager_views.h +++ b/ui/views/widget/tooltip_manager_views.h @@ -8,10 +8,10 @@ #include "base/message_loop.h" #include "base/timer.h" +#include "ui/views/controls/label.h" #include "ui/views/widget/native_widget.h" #include "ui/views/widget/tooltip_manager.h" #include "ui/views/widget/widget_delegate.h" -#include "views/controls/label.h" #include "views/view.h" #if defined(USE_X11) diff --git a/views/controls/label.cc b/views/controls/label.cc deleted file mode 100644 index 5473eb4..0000000 --- a/views/controls/label.cc +++ /dev/null @@ -1,503 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/controls/label.h" - -#include -#include -#include -#include - -#include "base/i18n/rtl.h" -#include "base/logging.h" -#include "base/string_split.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/base/text/text_elider.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/color_utils.h" -#include "ui/gfx/font.h" -#include "ui/gfx/insets.h" -#include "views/background.h" - -namespace views { - -// static -const char Label::kViewClassName[] = "views/Label"; - -const int Label::kFocusBorderPadding = 1; - -Label::Label() { - Init(string16(), GetDefaultFont()); -} - -Label::Label(const string16& text) { - Init(text, GetDefaultFont()); -} - -Label::Label(const string16& text, const gfx::Font& font) { - Init(text, font); -} - -Label::~Label() { -} - -void Label::SetFont(const gfx::Font& font) { - font_ = font; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); -} - -void Label::SetText(const string16& text) { - text_ = text; - url_set_ = false; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); -} - -const string16 Label::GetText() const { - return url_set_ ? UTF8ToUTF16(url_.spec()) : text_; -} - -void Label::SetURL(const GURL& url) { - url_ = url; - text_ = UTF8ToUTF16(url_.spec()); - url_set_ = true; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); -} - -const GURL Label::GetURL() const { - return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); -} - -void Label::SetAutoColorReadabilityEnabled(bool enabled) { - auto_color_readability_ = enabled; - RecalculateColors(); -} - -void Label::SetEnabledColor(const SkColor& color) { - requested_enabled_color_ = color; - RecalculateColors(); -} - -void Label::SetDisabledColor(const SkColor& color) { - requested_disabled_color_ = color; - RecalculateColors(); -} - -void Label::SetBackgroundColor(const SkColor& color) { - background_color_ = color; - RecalculateColors(); -} - -void Label::SetHorizontalAlignment(Alignment alignment) { - // If the View's UI layout is right-to-left and rtl_alignment_mode_ is - // USE_UI_ALIGNMENT, we need to flip the alignment so that the alignment - // settings take into account the text directionality. - if (base::i18n::IsRTL() && (rtl_alignment_mode_ == USE_UI_ALIGNMENT) && - (alignment != ALIGN_CENTER)) - alignment = (alignment == ALIGN_LEFT) ? ALIGN_RIGHT : ALIGN_LEFT; - if (horiz_alignment_ != alignment) { - horiz_alignment_ = alignment; - SchedulePaint(); - } -} - -void Label::SetMultiLine(bool multi_line) { - DCHECK(!multi_line || !elide_in_middle_); - if (multi_line != is_multi_line_) { - is_multi_line_ = multi_line; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); - } -} - -void Label::SetAllowCharacterBreak(bool allow_character_break) { - if (allow_character_break != allow_character_break_) { - allow_character_break_ = allow_character_break; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); - } -} - -void Label::SetElideInMiddle(bool elide_in_middle) { - DCHECK(!elide_in_middle || !is_multi_line_); - if (elide_in_middle != elide_in_middle_) { - elide_in_middle_ = elide_in_middle; - text_size_valid_ = false; - PreferredSizeChanged(); - SchedulePaint(); - } -} - -void Label::SetTooltipText(const string16& tooltip_text) { - tooltip_text_ = tooltip_text; -} - -void Label::SetMouseOverBackground(Background* background) { - mouse_over_background_.reset(background); -} - -const Background* Label::GetMouseOverBackground() const { - return mouse_over_background_.get(); -} - -void Label::SizeToFit(int max_width) { - DCHECK(is_multi_line_); - - std::vector lines; - base::SplitString(text_, '\n', &lines); - - int label_width = 0; - for (std::vector::const_iterator iter = lines.begin(); - iter != lines.end(); ++iter) { - label_width = std::max(label_width, font_.GetStringWidth(*iter)); - } - - label_width += GetInsets().width(); - - if (max_width > 0) - label_width = std::min(label_width, max_width); - - SetBounds(x(), y(), label_width, 0); - SizeToPreferredSize(); -} - -void Label::SetHasFocusBorder(bool has_focus_border) { - has_focus_border_ = has_focus_border; - if (is_multi_line_) { - text_size_valid_ = false; - PreferredSizeChanged(); - } -} - -gfx::Insets Label::GetInsets() const { - gfx::Insets insets = View::GetInsets(); - if (IsFocusable() || has_focus_border_) { - insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, - kFocusBorderPadding, kFocusBorderPadding); - } - return insets; -} - -int Label::GetBaseline() const { - return GetInsets().top() + font_.GetBaseline(); -} - -gfx::Size Label::GetPreferredSize() { - // Return a size of (0, 0) if the label is not visible and if the - // collapse_when_hidden_ flag is set. - // TODO(munjal): This logic probably belongs to the View class. But for now, - // put it here since putting it in View class means all inheriting classes - // need ot respect the collapse_when_hidden_ flag. - if (!IsVisible() && collapse_when_hidden_) - return gfx::Size(); - - gfx::Size prefsize(GetTextSize()); - gfx::Insets insets = GetInsets(); - prefsize.Enlarge(insets.width(), insets.height()); - return prefsize; -} - -int Label::GetHeightForWidth(int w) { - if (!is_multi_line_) - return View::GetHeightForWidth(w); - - w = std::max(0, w - GetInsets().width()); - int h = font_.GetHeight(); - gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, - ComputeMultiLineFlags()); - return h + GetInsets().height(); -} - -std::string Label::GetClassName() const { - return kViewClassName; -} - -bool Label::HitTest(const gfx::Point& l) const { - return false; -} - -void Label::OnMouseMoved(const MouseEvent& event) { - UpdateContainsMouse(event); -} - -void Label::OnMouseEntered(const MouseEvent& event) { - UpdateContainsMouse(event); -} - -void Label::OnMouseExited(const MouseEvent& event) { - SetContainsMouse(false); -} - -bool Label::GetTooltipText(const gfx::Point& p, string16* tooltip) const { - DCHECK(tooltip); - - // If a tooltip has been explicitly set, use it. - if (!tooltip_text_.empty()) { - tooltip->assign(tooltip_text_); - return true; - } - - // Show the full text if the text does not fit. - if (!is_multi_line_ && - (font_.GetStringWidth(text_) > GetAvailableRect().width())) { - *tooltip = text_; - return true; - } - return false; -} - -void Label::GetAccessibleState(ui::AccessibleViewState* state) { - state->role = ui::AccessibilityTypes::ROLE_STATICTEXT; - state->state = ui::AccessibilityTypes::STATE_READONLY; - state->name = text_; -} - -void Label::PaintText(gfx::Canvas* canvas, - const string16& text, - const gfx::Rect& text_bounds, - int flags) { - canvas->DrawStringInt(text, font_, - IsEnabled() ? actual_enabled_color_ : actual_disabled_color_, - text_bounds.x(), text_bounds.y(), text_bounds.width(), - text_bounds.height(), flags); - - if (HasFocus() || paint_as_focused_) { - gfx::Rect focus_bounds = text_bounds; - focus_bounds.Inset(-kFocusBorderPadding, -kFocusBorderPadding); - canvas->DrawFocusRect(focus_bounds); - } -} - -gfx::Size Label::GetTextSize() const { - if (!text_size_valid_) { - // For single-line strings, we supply the largest possible width, because - // while adding NO_ELLIPSIS to the flags works on Windows for forcing - // SizeStringInt() to calculate the desired width, it doesn't seem to work - // on Linux. - int w = is_multi_line_ ? - GetAvailableRect().width() : std::numeric_limits::max(); - int h = font_.GetHeight(); - // For single-line strings, ignore the available width and calculate how - // wide the text wants to be. - int flags = ComputeMultiLineFlags(); - if (!is_multi_line_) - flags |= gfx::Canvas::NO_ELLIPSIS; - gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); - text_size_.SetSize(w, h); - text_size_valid_ = true; - } - - return text_size_; -} - -void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) { - text_size_valid_ &= !is_multi_line_; -} - -void Label::OnPaint(gfx::Canvas* canvas) { - OnPaintBackground(canvas); - - string16 paint_text; - gfx::Rect text_bounds; - int flags = 0; - CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - PaintText(canvas, paint_text, text_bounds, flags); -} - -void Label::OnPaintBackground(gfx::Canvas* canvas) { - const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL; - if (!bg) - bg = background(); - if (bg) - bg->Paint(canvas, this); -} - -// static -gfx::Font Label::GetDefaultFont() { - return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); -} - -void Label::Init(const string16& text, const gfx::Font& font) { - static bool initialized = false; - static SkColor kDefaultEnabledColor; - static SkColor kDefaultDisabledColor; - static SkColor kDefaultBackgroundColor; - if (!initialized) { -#if defined(OS_WIN) - kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); - kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); - kDefaultBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); -#else - // TODO(beng): source from theme provider. - kDefaultEnabledColor = SK_ColorBLACK; - kDefaultDisabledColor = SK_ColorGRAY; - kDefaultBackgroundColor = SK_ColorWHITE; -#endif - - initialized = true; - } - - contains_mouse_ = false; - font_ = font; - text_size_valid_ = false; - url_set_ = false; - requested_enabled_color_ = kDefaultEnabledColor; - requested_disabled_color_ = kDefaultDisabledColor; - background_color_ = kDefaultBackgroundColor; - auto_color_readability_ = true; - RecalculateColors(); - horiz_alignment_ = ALIGN_CENTER; - is_multi_line_ = false; - allow_character_break_ = false; - elide_in_middle_ = false; - collapse_when_hidden_ = false; - rtl_alignment_mode_ = USE_UI_ALIGNMENT; - paint_as_focused_ = false; - has_focus_border_ = false; - - SetText(text); -} - -void Label::RecalculateColors() { - actual_enabled_color_ = auto_color_readability_ ? - color_utils::GetReadableColor(requested_enabled_color_, - background_color_) : - requested_enabled_color_; - actual_disabled_color_ = auto_color_readability_ ? - color_utils::GetReadableColor(requested_disabled_color_, - background_color_) : - requested_disabled_color_; -} - -void Label::UpdateContainsMouse(const MouseEvent& event) { - SetContainsMouse(GetTextBounds().Contains(event.x(), event.y())); -} - -void Label::SetContainsMouse(bool contains_mouse) { - if (contains_mouse_ == contains_mouse) - return; - contains_mouse_ = contains_mouse; - if (GetMouseOverBackground()) - SchedulePaint(); -} - -gfx::Rect Label::GetTextBounds() const { - gfx::Rect available_rect(GetAvailableRect()); - gfx::Size text_size(GetTextSize()); - text_size.set_width(std::min(available_rect.width(), text_size.width())); - - gfx::Insets insets = GetInsets(); - gfx::Point text_origin(insets.left(), insets.top()); - switch (horiz_alignment_) { - case ALIGN_LEFT: - break; - case ALIGN_CENTER: - // We put any extra margin pixel on the left rather than the right. We - // used to do this because measurement on Windows used - // GetTextExtentPoint32(), which could report a value one too large on the - // right; we now use DrawText(), and who knows if it can also do this. - text_origin.Offset((available_rect.width() + 1 - text_size.width()) / 2, - 0); - break; - case ALIGN_RIGHT: - text_origin.set_x(available_rect.right() - text_size.width()); - break; - default: - NOTREACHED(); - break; - } - text_origin.Offset(0, - std::max(0, (available_rect.height() - text_size.height())) / 2); - return gfx::Rect(text_origin, text_size); -} - -int Label::ComputeMultiLineFlags() const { - if (!is_multi_line_) - return 0; - - int flags = gfx::Canvas::MULTI_LINE; -#if !defined(OS_WIN) - // Don't elide multiline labels on Linux. - // Todo(davemoore): Do we depend on eliding multiline text? - // Pango insists on limiting the number of lines to one if text is - // elided. You can get around this if you can pass a maximum height - // but we don't currently have that data when we call the pango code. - flags |= gfx::Canvas::NO_ELLIPSIS; -#endif - if (allow_character_break_) - flags |= gfx::Canvas::CHARACTER_BREAK; - switch (horiz_alignment_) { - case ALIGN_LEFT: - flags |= gfx::Canvas::TEXT_ALIGN_LEFT; - break; - case ALIGN_CENTER: - flags |= gfx::Canvas::TEXT_ALIGN_CENTER; - break; - case ALIGN_RIGHT: - flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; - break; - } - return flags; -} - -gfx::Rect Label::GetAvailableRect() const { - gfx::Rect bounds(gfx::Point(), size()); - gfx::Insets insets(GetInsets()); - bounds.Inset(insets.left(), insets.top(), insets.right(), insets.bottom()); - return bounds; -} - -void Label::CalculateDrawStringParams(string16* paint_text, - gfx::Rect* text_bounds, - int* flags) const { - DCHECK(paint_text && text_bounds && flags); - - if (url_set_) { - // TODO(jungshik) : Figure out how to get 'intl.accept_languages' - // preference and use it when calling ElideUrl. - *paint_text = - ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string()); - - // An URLs is always treated as an LTR text and therefore we should - // explicitly mark it as such if the locale is RTL so that URLs containing - // Hebrew or Arabic characters are displayed correctly. - // - // Note that we don't check the View's UI layout setting in order to - // determine whether or not to insert the special Unicode formatting - // characters. We use the locale settings because an URL is always treated - // as an LTR string, even if its containing view does not use an RTL UI - // layout. - *paint_text = base::i18n::GetDisplayStringInLTRDirectionality( - *paint_text); - } else if (elide_in_middle_) { - *paint_text = ui::ElideText(text_, - font_, GetAvailableRect().width(), true); - } else { - *paint_text = text_; - } - - *text_bounds = GetTextBounds(); - *flags = ComputeMultiLineFlags(); - // If rtl_alignment_mode_ is AUTO_DETECT_ALIGNMENT (such as for text from - // webpage, not from chrome's UI), its directionality is forced to be RTL if - // it is right aligned. Otherwise, its directionality is forced to be LTR. - if (rtl_alignment_mode_ == AUTO_DETECT_ALIGNMENT) { - if (horiz_alignment_ == ALIGN_RIGHT) - *flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY; - else - *flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY; - } -} - -} // namespace views diff --git a/views/controls/label.h b/views/controls/label.h deleted file mode 100644 index bf60ead..0000000 --- a/views/controls/label.h +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_CONTROLS_LABEL_H_ -#define VIEWS_CONTROLS_LABEL_H_ -#pragma once - -#include - -#include "base/compiler_specific.h" -#include "base/gtest_prod_util.h" -#include "base/string16.h" -#include "googleurl/src/gurl.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/gfx/font.h" -#include "views/view.h" - -namespace views { - -///////////////////////////////////////////////////////////////////////////// -// -// Label class -// -// A label is a view subclass that can display a string. -// -///////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT Label : public View { - public: - enum Alignment { ALIGN_LEFT = 0, - ALIGN_CENTER, - ALIGN_RIGHT }; - - // The following enum is used to indicate whether using the Chrome UI's - // alignment as the label's alignment, or autodetecting the label's - // alignment. - // - // If the label text originates from the Chrome UI, we should use the Chrome - // UI's alignment as the label's alignment. - // - // If the text originates from a web page, the text's alignment is determined - // based on the first character with strong directionality, disregarding what - // directionality the Chrome UI is. And its alignment will not be flipped - // around in RTL locales. - enum RTLAlignmentMode { - USE_UI_ALIGNMENT = 0, - AUTO_DETECT_ALIGNMENT - }; - - // The view class name. - static const char kViewClassName[]; - - // The padding for the focus border when rendering focused text. - static const int kFocusBorderPadding; - - Label(); - explicit Label(const string16& text); - Label(const string16& text, const gfx::Font& font); - virtual ~Label(); - - // Set the font. - virtual void SetFont(const gfx::Font& font); - - // Set the label text. - void SetText(const string16& text); - - // Return the font used by this label. - gfx::Font font() const { return font_; } - - // Return the label text. - const string16 GetText() const; - - // Set URL Value - text_ is set to spec(). - void SetURL(const GURL& url); - - // Return the label URL. - const GURL GetURL() const; - - // Enables or disables auto-color-readability (enabled by default). If this - // is enabled, then calls to set any foreground or background color will - // trigger an automatic mapper that uses color_utils::GetReadableColor() to - // ensure that the foreground colors are readable over the background color. - void SetAutoColorReadabilityEnabled(bool enabled); - - // Set the color. This will automatically force the color to be readable - // over the current background color. - virtual void SetEnabledColor(const SkColor& color); - void SetDisabledColor(const SkColor& color); - - SkColor enabled_color() const { return actual_enabled_color_; } - - // Set the background color. This won't be explicitly drawn, but the label - // will force the text color to be readable over it. - void SetBackgroundColor(const SkColor& color); - - // Set horizontal alignment. If the locale is RTL, and the RTL alignment - // setting is set as USE_UI_ALIGNMENT, the alignment is flipped around. - // - // Caveat: for labels originating from a web page, the RTL alignment mode - // should be reset to AUTO_DETECT_ALIGNMENT before the horizontal alignment - // is set. Otherwise, the label's alignment specified as a parameter will be - // flipped in RTL locales. Please see the comments in SetRTLAlignmentMode for - // more information. - void SetHorizontalAlignment(Alignment alignment); - - Alignment horizontal_alignment() const { return horiz_alignment_; } - - // Set the RTL alignment mode. The RTL alignment mode is initialized to - // USE_UI_ALIGNMENT when the label is constructed. USE_UI_ALIGNMENT applies - // to every label that originates from the Chrome UI. However, if the label - // originates from a web page, its alignment should not be flipped around for - // RTL locales. For such labels, we need to set the RTL alignment mode to - // AUTO_DETECT_ALIGNMENT so that subsequent SetHorizontalAlignment() calls - // will not flip the label's alignment around. - void set_rtl_alignment_mode(RTLAlignmentMode mode) { - rtl_alignment_mode_ = mode; - } - RTLAlignmentMode rtl_alignment_mode() const { return rtl_alignment_mode_; } - - // Set whether the label text can wrap on multiple lines. - // Default is false. - void SetMultiLine(bool multi_line); - - // Return whether the label text can wrap on multiple lines. - bool is_multi_line() const { return is_multi_line_; } - - // Set whether the label text can be split on words. - // Default is false. This only works when is_multi_line is true. - void SetAllowCharacterBreak(bool allow_character_break); - - // Set whether the label text should be elided in the middle (if necessary). - // The default is to elide at the end. - // NOTE: This is not supported for multi-line strings. - void SetElideInMiddle(bool elide_in_middle); - - // Sets the tooltip text. Default behavior for a label (single-line) is to - // show the full text if it is wider than its bounds. Calling this overrides - // the default behavior and lets you set a custom tooltip. To revert to - // default behavior, call this with an empty string. - void SetTooltipText(const string16& tooltip_text); - - // The background color to use when the mouse is over the label. Label - // takes ownership of the Background. - void SetMouseOverBackground(Background* background); - const Background* GetMouseOverBackground() const; - - // Resizes the label so its width is set to the width of the longest line and - // its height deduced accordingly. - // This is only intended for multi-line labels and is useful when the label's - // text contains several lines separated with \n. - // |max_width| is the maximum width that will be used (longer lines will be - // wrapped). If 0, no maximum width is enforced. - void SizeToFit(int max_width); - - // Gets/sets the flag to determine whether the label should be collapsed when - // it's hidden (not visible). If this flag is true, the label will return a - // preferred size of (0, 0) when it's not visible. - void set_collapse_when_hidden(bool value) { collapse_when_hidden_ = value; } - bool collapse_when_hidden() const { return collapse_when_hidden_; } - - // Gets/set whether or not this label is to be painted as a focused element. - void set_paint_as_focused(bool paint_as_focused) { - paint_as_focused_ = paint_as_focused; - } - bool paint_as_focused() const { return paint_as_focused_; } - - void SetHasFocusBorder(bool has_focus_border); - - // Overridden from View: - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual int GetBaseline() const OVERRIDE; - // Overridden to compute the size required to display this label. - virtual gfx::Size GetPreferredSize() OVERRIDE; - // Return the height necessary to display this label with the provided width. - // This method is used to layout multi-line labels. It is equivalent to - // GetPreferredSize().height() if the receiver is not multi-line. - virtual int GetHeightForWidth(int w) OVERRIDE; - virtual std::string GetClassName() const OVERRIDE; - virtual bool HitTest(const gfx::Point& l) const OVERRIDE; - // Mouse enter/exit are overridden to render mouse over background color. - // These invoke SetContainsMouse as necessary. - virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; - virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE; - virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - // Gets the tooltip text for labels that are wider than their bounds, except - // when the label is multiline, in which case it just returns false (no - // tooltip). If a custom tooltip has been specified with SetTooltipText() - // it is returned instead. - virtual bool GetTooltipText(const gfx::Point& p, - string16* tooltip) const OVERRIDE; - - protected: - // Called by Paint to paint the text. Override this to change how - // text is painted. - virtual void PaintText(gfx::Canvas* canvas, - const string16& text, - const gfx::Rect& text_bounds, - int flags); - - void invalidate_text_size() { text_size_valid_ = false; } - - virtual gfx::Size GetTextSize() const; - - SkColor disabled_color() const { return actual_disabled_color_; } - - // Overridden from View: - // Overridden to dirty our text bounds if we're multi-line. - virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - // If the mouse is over the label, and a mouse over background has been - // specified, its used. Otherwise super's implementation is invoked. - virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; - - private: - // These tests call CalculateDrawStringParams in order to verify the - // calculations done for drawing text. - FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); - FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); - FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); - FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); - - static gfx::Font GetDefaultFont(); - - void Init(const string16& text, const gfx::Font& font); - - void RecalculateColors(); - - // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise - // SetContainsMouse(false) is invoked. - void UpdateContainsMouse(const MouseEvent& event); - - // Updates whether the mouse is contained in the Label. If the new value - // differs from the current value, and a mouse over background is specified, - // SchedulePaint is invoked. - void SetContainsMouse(bool contains_mouse); - - // Returns where the text is drawn, in the receivers coordinate system. - gfx::Rect GetTextBounds() const; - - int ComputeMultiLineFlags() const; - - gfx::Rect GetAvailableRect() const; - - // Returns parameters to be used for the DrawString call. - void CalculateDrawStringParams(string16* paint_text, - gfx::Rect* text_bounds, - int* flags) const; - - string16 text_; - GURL url_; - gfx::Font font_; - SkColor requested_enabled_color_; - SkColor actual_enabled_color_; - SkColor requested_disabled_color_; - SkColor actual_disabled_color_; - SkColor background_color_; - bool auto_color_readability_; - mutable gfx::Size text_size_; - mutable bool text_size_valid_; - bool is_multi_line_; - bool allow_character_break_; - bool elide_in_middle_; - bool url_set_; - Alignment horiz_alignment_; - string16 tooltip_text_; - // Whether the mouse is over this label. - bool contains_mouse_; - scoped_ptr mouse_over_background_; - // Whether to collapse the label when it's not visible. - bool collapse_when_hidden_; - // The following member variable is used to control whether the alignment - // needs to be flipped around for RTL locales. Please refer to the definition - // of RTLAlignmentMode for more information. - RTLAlignmentMode rtl_alignment_mode_; - // When embedded in a larger control that is focusable, setting this flag - // allows this view to be painted as focused even when it is itself not. - bool paint_as_focused_; - // When embedded in a larger control that is focusable, setting this flag - // allows this view to reserve space for a focus border that it otherwise - // might not have because it is not itself focusable. - bool has_focus_border_; - - DISALLOW_COPY_AND_ASSIGN(Label); -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_LABEL_H_ diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc deleted file mode 100644 index cbb769a..0000000 --- a/views/controls/label_unittest.cc +++ /dev/null @@ -1,811 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/i18n/rtl.h" -#include "base/utf_string_conversions.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/canvas.h" -#include "views/border.h" -#include "views/controls/label.h" - -namespace views { - -// All text sizing measurements (width and height) should be greater than this. -const int kMinTextDimension = 4; - -#if defined(OS_WIN) -// Courier is failing on linux because it's non scalable. -TEST(LabelTest, FontPropertyCourier) { - Label label; - std::string font_name("courier"); - gfx::Font font(font_name, 30); - label.SetFont(font); - gfx::Font font_used = label.font(); - EXPECT_EQ(font_name, font_used.GetFontName()); - EXPECT_EQ(30, font_used.GetFontSize()); -} -#endif - -TEST(LabelTest, FontPropertyArial) { - Label label; - std::string font_name("arial"); - gfx::Font font(font_name, 30); - label.SetFont(font); - gfx::Font font_used = label.font(); - EXPECT_EQ(font_name, font_used.GetFontName()); - EXPECT_EQ(30, font_used.GetFontSize()); -} - -TEST(LabelTest, TextProperty) { - Label label; - string16 test_text(ASCIIToUTF16("A random string.")); - label.SetText(test_text); - EXPECT_EQ(test_text, label.GetText()); -} - -TEST(LabelTest, UrlProperty) { - Label label; - std::string my_url("http://www.orkut.com/some/Random/path"); - GURL url(my_url); - label.SetURL(url); - EXPECT_EQ(my_url, label.GetURL().spec()); - EXPECT_EQ(UTF8ToUTF16(my_url), label.GetText()); -} - -TEST(LabelTest, ColorProperty) { - Label label; - SkColor color = SkColorSetARGB(20, 40, 10, 5); - label.SetAutoColorReadabilityEnabled(false); - label.SetEnabledColor(color); - EXPECT_EQ(color, label.enabled_color()); -} - -TEST(LabelTest, AlignmentProperty) { - Label label; - bool reverse_alignment = base::i18n::IsRTL(); - - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - EXPECT_EQ( - reverse_alignment ? Label::ALIGN_LEFT : Label::ALIGN_RIGHT, - label.horizontal_alignment()); - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - EXPECT_EQ( - reverse_alignment ? Label::ALIGN_RIGHT : Label::ALIGN_LEFT, - label.horizontal_alignment()); - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); - - // The label's alignment should not be flipped if the RTL alignment mode - // is AUTO_DETECT_ALIGNMENT. - label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - EXPECT_EQ(Label::ALIGN_RIGHT, label.horizontal_alignment()); - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - EXPECT_EQ(Label::ALIGN_LEFT, label.horizontal_alignment()); - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); -} - -TEST(LabelTest, RTLAlignmentModeProperty) { - Label label; - EXPECT_EQ(Label::USE_UI_ALIGNMENT, label.rtl_alignment_mode()); - - label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); - EXPECT_EQ(Label::AUTO_DETECT_ALIGNMENT, label.rtl_alignment_mode()); - - label.set_rtl_alignment_mode(Label::USE_UI_ALIGNMENT); - EXPECT_EQ(Label::USE_UI_ALIGNMENT, label.rtl_alignment_mode()); -} - -TEST(LabelTest, MultiLineProperty) { - Label label; - EXPECT_FALSE(label.is_multi_line()); - label.SetMultiLine(true); - EXPECT_TRUE(label.is_multi_line()); - label.SetMultiLine(false); - EXPECT_FALSE(label.is_multi_line()); -} - -TEST(LabelTest, TooltipProperty) { - Label label; - string16 test_text(ASCIIToUTF16("My cool string.")); - label.SetText(test_text); - - string16 tooltip; - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - EXPECT_EQ(test_text, tooltip); - - string16 tooltip_text(ASCIIToUTF16("The tooltip!")); - label.SetTooltipText(tooltip_text); - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - EXPECT_EQ(tooltip_text, tooltip); - - string16 empty_text; - label.SetTooltipText(empty_text); - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - EXPECT_EQ(test_text, tooltip); - - // Make the label big enough to hold the text - // and expect there to be no tooltip. - label.SetBounds(0, 0, 1000, 40); - EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); - - // Verify that setting the tooltip still shows it. - label.SetTooltipText(tooltip_text); - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - EXPECT_EQ(tooltip_text, tooltip); - // Clear out the tooltip. - label.SetTooltipText(empty_text); - - // Shrink the bounds and the tooltip should come back. - label.SetBounds(0, 0, 1, 1); - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - - // Make the label multiline and there is no tooltip again. - label.SetMultiLine(true); - EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); - - // Verify that setting the tooltip still shows it. - label.SetTooltipText(tooltip_text); - EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); - EXPECT_EQ(tooltip_text, tooltip); - // Clear out the tooltip. - label.SetTooltipText(empty_text); -} - -TEST(LabelTest, Accessibility) { - Label label; - string16 test_text(ASCIIToUTF16("My special text.")); - label.SetText(test_text); - - ui::AccessibleViewState state; - label.GetAccessibleState(&state); - EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); - EXPECT_EQ(test_text, state.name); - EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); -} - -TEST(LabelTest, SingleLineSizing) { - Label label; - string16 test_text(ASCIIToUTF16("A not so random string in one line.")); - label.SetText(test_text); - - // GetPreferredSize - gfx::Size required_size = label.GetPreferredSize(); - EXPECT_GT(required_size.height(), kMinTextDimension); - EXPECT_GT(required_size.width(), kMinTextDimension); - - // Test everything with borders. - gfx::Insets border(10, 20, 30, 40); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - - // GetPreferredSize and borders. - label.SetBounds(0, 0, 0, 0); - gfx::Size required_size_with_border = label.GetPreferredSize(); - EXPECT_EQ(required_size_with_border.height(), - required_size.height() + border.height()); - EXPECT_EQ(required_size_with_border.width(), - required_size.width() + border.width()); -} - -TEST(LabelTest, MultiLineSizing) { - Label label; - label.set_focusable(false); - string16 test_text( - ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); - label.SetText(test_text); - label.SetMultiLine(true); - - // GetPreferredSize - gfx::Size required_size = label.GetPreferredSize(); - EXPECT_GT(required_size.height(), kMinTextDimension); - EXPECT_GT(required_size.width(), kMinTextDimension); - - // SizeToFit with unlimited width. - label.SizeToFit(0); - int required_width = label.GetLocalBounds().width(); - EXPECT_GT(required_width, kMinTextDimension); - - // SizeToFit with limited width. - label.SizeToFit(required_width - 1); - int constrained_width = label.GetLocalBounds().width(); -#if defined(OS_WIN) - // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) - // has to be fixed to return the size that fits to given width/height. - EXPECT_LT(constrained_width, required_width); -#endif - EXPECT_GT(constrained_width, kMinTextDimension); - - // Change the width back to the desire width. - label.SizeToFit(required_width); - EXPECT_EQ(required_width, label.GetLocalBounds().width()); - - // General tests for GetHeightForWidth. - int required_height = label.GetHeightForWidth(required_width); - EXPECT_GT(required_height, kMinTextDimension); - int height_for_constrained_width = label.GetHeightForWidth(constrained_width); -#if defined(OS_WIN) - // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) - // has to be fixed to return the size that fits to given width/height. - EXPECT_GT(height_for_constrained_width, required_height); -#endif - // Using the constrained width or the required_width - 1 should give the - // same result for the height because the constrainted width is the tight - // width when given "required_width - 1" as the max width. - EXPECT_EQ(height_for_constrained_width, - label.GetHeightForWidth(required_width - 1)); - - // Test everything with borders. - gfx::Insets border(10, 20, 30, 40); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - - // SizeToFit and borders. - label.SizeToFit(0); - int required_width_with_border = label.GetLocalBounds().width(); - EXPECT_EQ(required_width_with_border, required_width + border.width()); - - // GetHeightForWidth and borders. - int required_height_with_border = - label.GetHeightForWidth(required_width_with_border); - EXPECT_EQ(required_height_with_border, required_height + border.height()); - - // Test that the border width is subtracted before doing the height - // calculation. If it is, then the height will grow when width - // is shrunk. - int height1 = label.GetHeightForWidth(required_width_with_border - 1); -#if defined(OS_WIN) - // Canvas::SizeStringInt (in ui/gfx/canvas_skia_linux.cc) - // has to be fixed to return the size that fits to given width/height. - EXPECT_GT(height1, required_height_with_border); -#endif - EXPECT_EQ(height1, height_for_constrained_width + border.height()); - - // GetPreferredSize and borders. - label.SetBounds(0, 0, 0, 0); - gfx::Size required_size_with_border = label.GetPreferredSize(); - EXPECT_EQ(required_size_with_border.height(), - required_size.height() + border.height()); - EXPECT_EQ(required_size_with_border.width(), - required_size.width() + border.width()); -} - -TEST(LabelTest, DrawSingleLineString) { - Label label; - label.set_focusable(false); - - // Turn off mirroring so that we don't need to figure out if - // align right really means align left. - label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); - - string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); - label.SetText(test_text); - gfx::Size required_size(label.GetPreferredSize()); - gfx::Size extra(22, 8); - label.SetBounds(0, - 0, - required_size.width() + extra.width(), - required_size.height() + extra.height()); - - // Do some basic verifications for all three alignments. - string16 paint_text; - gfx::Rect text_bounds; - int flags; - - // Centered text. - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be centered horizontally and vertically. - EXPECT_EQ(extra.width() / 2, text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); - - // Left aligned text. - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be left aligned horizontally and centered vertically. - EXPECT_EQ(0, text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); - - // Right aligned text. - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be right aligned horizontally and centered vertically. - EXPECT_EQ(extra.width(), text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); - - // Test single line drawing with a border. - gfx::Insets border(39, 34, 8, 96); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - - gfx::Size required_size_with_border(label.GetPreferredSize()); - EXPECT_EQ(required_size.width() + border.width(), - required_size_with_border.width()); - EXPECT_EQ(required_size.height() + border.height(), - required_size_with_border.height()); - label.SetBounds(0, - 0, - required_size_with_border.width() + extra.width(), - required_size_with_border.height() + extra.height()); - - // Centered text with border. - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be centered horizontally and vertically within the border. - EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); - - // Left aligned text with border. - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be left aligned horizontally and centered vertically. - EXPECT_EQ(border.left(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); - - // Right aligned text. - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be right aligned horizontally and centered vertically. - EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags); -} - -// On Linux the underlying pango routines require a max height in order to -// ellide multiline text. So until that can be resolved, we set all -// multiline lables to not ellide in Linux only. -TEST(LabelTest, DrawMultiLineString) { - Label label; - label.set_focusable(false); - - // Turn off mirroring so that we don't need to figure out if - // align right really means align left. - label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); - - string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); - label.SetText(test_text); - label.SetMultiLine(true); - label.SizeToFit(0); - gfx::Size extra(50, 10); - label.SetBounds(label.x(), - label.y(), - label.width() + extra.width(), - label.height() + extra.height()); - - // Do some basic verifications for all three alignments. - string16 paint_text; - gfx::Rect text_bounds; - int flags; - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(extra.width() / 2, text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); - int expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::FORCE_LTR_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif - gfx::Rect center_bounds(text_bounds); - - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(0, text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); - expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::FORCE_LTR_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(extra.width(), text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); - expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::FORCE_RTL_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif - - // Test multiline drawing with a border. - gfx::Insets border(19, 92, 23, 2); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - label.SizeToFit(0); - label.SetBounds(label.x(), - label.y(), - label.width() + extra.width(), - label.height() + extra.height()); - - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); - expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::FORCE_LTR_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(border.left(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); - expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::FORCE_LTR_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(extra.width() + border.left(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); - expected_flags = gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::FORCE_RTL_DIRECTIONALITY; -#if defined(OS_WIN) - EXPECT_EQ(expected_flags, flags); -#else - EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); -#endif -} - -TEST(LabelTest, DrawSingleLineStringInRTL) { - Label label; - label.set_focusable(false); - - std::string locale = l10n_util::GetApplicationLocale(""); - base::i18n::SetICUDefaultLocale("he"); - - string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); - label.SetText(test_text); - gfx::Size required_size(label.GetPreferredSize()); - gfx::Size extra(22, 8); - label.SetBounds(0, - 0, - required_size.width() + extra.width(), - required_size.height() + extra.height()); - - // Do some basic verifications for all three alignments. - string16 paint_text; - gfx::Rect text_bounds; - int flags; - - // Centered text. - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be centered horizontally and vertically. - EXPECT_EQ(extra.width() / 2, text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - // ALIGN_LEFT label. - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be right aligned horizontally and centered vertically. - EXPECT_EQ(extra.width(), text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - // ALIGN_RIGHT label. - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be left aligned horizontally and centered vertically. - EXPECT_EQ(0, text_bounds.x()); - EXPECT_EQ(extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - - // Test single line drawing with a border. - gfx::Insets border(39, 34, 8, 96); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - - gfx::Size required_size_with_border(label.GetPreferredSize()); - EXPECT_EQ(required_size.width() + border.width(), - required_size_with_border.width()); - EXPECT_EQ(required_size.height() + border.height(), - required_size_with_border.height()); - label.SetBounds(0, - 0, - required_size_with_border.width() + extra.width(), - required_size_with_border.height() + extra.height()); - - // Centered text with border. - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be centered horizontally and vertically within the border. - EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - // ALIGN_LEFT text with border. - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be right aligned horizontally and centered vertically. - EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - // ALIGN_RIGHT text. - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - // The text should be left aligned horizontally and centered vertically. - EXPECT_EQ(border.left(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); - EXPECT_EQ(required_size.width(), text_bounds.width()); - EXPECT_EQ(required_size.height(), text_bounds.height()); - EXPECT_EQ(0, flags); - - // Reset locale. - base::i18n::SetICUDefaultLocale(locale); -} - -// On Linux the underlying pango routines require a max height in order to -// ellide multiline text. So until that can be resolved, we set all -// multiline lables to not ellide in Linux only. -TEST(LabelTest, DrawMultiLineStringInRTL) { - Label label; - label.set_focusable(false); - - // Test for RTL. - std::string locale = l10n_util::GetApplicationLocale(""); - base::i18n::SetICUDefaultLocale("he"); - - string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); - label.SetText(test_text); - label.SetMultiLine(true); - label.SizeToFit(0); - gfx::Size extra(50, 10); - label.SetBounds(label.x(), - label.y(), - label.width() + extra.width(), - label.height() + extra.height()); - - // Do some basic verifications for all three alignments. - string16 paint_text; - gfx::Rect text_bounds; - int flags; - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(extra.width() / 2, text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - gfx::Rect center_bounds(text_bounds); - - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(extra.width(), text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(0, text_bounds.x()); - EXPECT_EQ(extra.height() / 2, text_bounds.y()); - EXPECT_GT(text_bounds.width(), kMinTextDimension); - EXPECT_GT(text_bounds.height(), kMinTextDimension); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - - // Test multiline drawing with a border. - gfx::Insets border(19, 92, 23, 2); - label.set_border(Border::CreateEmptyBorder(border.top(), - border.left(), - border.bottom(), - border.right())); - label.SizeToFit(0); - label.SetBounds(label.x(), - label.y(), - label.width() + extra.width(), - label.height() + extra.height()); - - label.SetHorizontalAlignment(Label::ALIGN_CENTER); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_CENTER | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_LEFT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_RIGHT | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - - label.SetHorizontalAlignment(Label::ALIGN_RIGHT); - paint_text.clear(); - text_bounds.SetRect(0, 0, 0, 0); - label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); - EXPECT_EQ(test_text, paint_text); - EXPECT_EQ(border.left(), text_bounds.x()); - EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); - EXPECT_EQ(center_bounds.width(), text_bounds.width()); - EXPECT_EQ(center_bounds.height(), text_bounds.height()); -#if defined(OS_WIN) - EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); -#else - EXPECT_EQ( - gfx::Canvas::MULTI_LINE | - gfx::Canvas::TEXT_ALIGN_LEFT | - gfx::Canvas::NO_ELLIPSIS, - flags); -#endif - - // Reset Locale - base::i18n::SetICUDefaultLocale(locale); -} - -} // namespace views diff --git a/views/controls/link.cc b/views/controls/link.cc deleted file mode 100644 index 8565bdf..0000000 --- a/views/controls/link.cc +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "views/controls/link.h" - -#include "build/build_config.h" - -#if defined(TOOLKIT_USES_GTK) -#include -#endif - -#include "base/logging.h" -#include "base/utf_string_conversions.h" -#include "ui/base/accessibility/accessible_view_state.h" -#include "ui/base/keycodes/keyboard_codes.h" -#include "ui/gfx/color_utils.h" -#include "ui/gfx/font.h" -#include "ui/views/events/event.h" -#include "views/controls/link_listener.h" - -#if defined(TOOLKIT_USES_GTK) -#include "ui/gfx/gtk_util.h" -#endif - -#if defined(USE_AURA) -#include "ui/aura/cursor.h" -#endif - -namespace views { - -const char Link::kViewClassName[] = "views/Link"; - -Link::Link() : Label(string16()) { - Init(); -} - -Link::Link(const string16& title) : Label(title) { - Init(); -} - -Link::~Link() { -} - -void Link::OnEnabledChanged() { - RecalculateFont(); - View::OnEnabledChanged(); -} - -std::string Link::GetClassName() const { - return kViewClassName; -} - -gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { - if (!IsEnabled()) - return gfx::kNullCursor; -#if defined(USE_AURA) - return aura::kCursorHand; -#elif defined(OS_WIN) - static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); - return g_hand_cursor; -#elif defined(TOOLKIT_USES_GTK) - return gfx::GetCursor(GDK_HAND2); -#endif -} - -bool Link::HitTest(const gfx::Point& l) const { - // We need to allow clicks on the link. So we override the implementation in - // Label and use the default implementation of View. - return View::HitTest(l); -} - -bool Link::OnMousePressed(const MouseEvent& event) { - if (!IsEnabled() || - (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) - return false; - SetPressed(true); - return true; -} - -bool Link::OnMouseDragged(const MouseEvent& event) { - SetPressed(IsEnabled() && - (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && - HitTest(event.location())); - return true; -} - -void Link::OnMouseReleased(const MouseEvent& event) { - // Change the highlight first just in case this instance is deleted - // while calling the controller - OnMouseCaptureLost(); - if (IsEnabled() && - (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && - HitTest(event.location())) { - // Focus the link on click. - RequestFocus(); - - if (listener_) - listener_->LinkClicked(this, event.flags()); - } -} - -void Link::OnMouseCaptureLost() { - SetPressed(false); -} - -bool Link::OnKeyPressed(const KeyEvent& event) { - bool activate = ((event.key_code() == ui::VKEY_SPACE) || - (event.key_code() == ui::VKEY_RETURN)); - if (!activate) - return false; - - SetPressed(false); - - // Focus the link on key pressed. - RequestFocus(); - - if (listener_) - listener_->LinkClicked(this, event.flags()); - - return true; -} - -bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& event) { - // Make sure we don't process space or enter as accelerators. - return (event.key_code() == ui::VKEY_SPACE) || - (event.key_code() == ui::VKEY_RETURN); -} - -void Link::GetAccessibleState(ui::AccessibleViewState* state) { - Label::GetAccessibleState(state); - state->role = ui::AccessibilityTypes::ROLE_LINK; -} - -void Link::SetFont(const gfx::Font& font) { - Label::SetFont(font); - RecalculateFont(); -} - -void Link::SetEnabledColor(const SkColor& color) { - requested_enabled_color_ = color; - if (!pressed_) - Label::SetEnabledColor(requested_enabled_color_); -} - -void Link::SetPressedColor(const SkColor& color) { - requested_pressed_color_ = color; - if (pressed_) - Label::SetEnabledColor(requested_pressed_color_); -} - -void Link::Init() { - static bool initialized = false; - static SkColor kDefaultEnabledColor; - static SkColor kDefaultDisabledColor; - static SkColor kDefaultPressedColor; - if (!initialized) { -#if defined(OS_WIN) - kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); - kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); - kDefaultPressedColor = SkColorSetRGB(200, 0, 0); -#else - // TODO(beng): source from theme provider. - kDefaultEnabledColor = SkColorSetRGB(0, 51, 153); - kDefaultDisabledColor = SK_ColorBLACK; - kDefaultPressedColor = SK_ColorRED; -#endif - - initialized = true; - } - - listener_ = NULL; - pressed_ = false; - SetEnabledColor(kDefaultEnabledColor); - SetDisabledColor(kDefaultDisabledColor); - SetPressedColor(kDefaultPressedColor); - RecalculateFont(); - set_focusable(true); -} - -void Link::SetPressed(bool pressed) { - if (pressed_ != pressed) { - pressed_ = pressed; - Label::SetEnabledColor(pressed_ ? - requested_pressed_color_ : requested_enabled_color_); - RecalculateFont(); - SchedulePaint(); - } -} - -void Link::RecalculateFont() { - // The font should be underlined iff the link is enabled. - if (IsEnabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { - Label::SetFont(font().DeriveFont(0, IsEnabled() ? - (font().GetStyle() | gfx::Font::UNDERLINED) : - (font().GetStyle() & ~gfx::Font::UNDERLINED))); - } -} - -} // namespace views diff --git a/views/controls/link.h b/views/controls/link.h deleted file mode 100644 index 4a07f46..0000000 --- a/views/controls/link.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_CONTROLS_LINK_H_ -#define VIEWS_CONTROLS_LINK_H_ -#pragma once - -#include - -#include "views/controls/label.h" - -namespace views { - -class LinkListener; - -//////////////////////////////////////////////////////////////////////////////// -// -// Link class -// -// A Link is a label subclass that looks like an HTML link. It has a -// controller which is notified when a click occurs. -// -//////////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT Link : public Label { - public: - Link(); - explicit Link(const string16& title); - virtual ~Link(); - - const LinkListener* listener() { return listener_; } - void set_listener(LinkListener* listener) { listener_ = listener; } - - // Overridden from View: - virtual void OnEnabledChanged() OVERRIDE; - virtual std::string GetClassName() const OVERRIDE; - virtual gfx::NativeCursor GetCursor(const MouseEvent& event) OVERRIDE; - virtual bool HitTest(const gfx::Point& l) const OVERRIDE; - virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE; - virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE; - virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE; - virtual void OnMouseCaptureLost() OVERRIDE; - virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; - virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& event) OVERRIDE; - virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - - // Overridden from Label: - virtual void SetFont(const gfx::Font& font) OVERRIDE; - - virtual void SetEnabledColor(const SkColor& color) OVERRIDE; - void SetPressedColor(const SkColor& color); - - static const char kViewClassName[]; - - private: - void Init(); - - void SetPressed(bool pressed); - - void RecalculateFont(); - - LinkListener* listener_; - - // Whether the link is currently pressed. - bool pressed_; - - // The color when the link is neither pressed nor disabled. - SkColor requested_enabled_color_; - - // The color when the link is pressed. - SkColor requested_pressed_color_; - - DISALLOW_COPY_AND_ASSIGN(Link); -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_LINK_H_ diff --git a/views/controls/link_listener.h b/views/controls/link_listener.h deleted file mode 100644 index d0d593e..0000000 --- a/views/controls/link_listener.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef VIEWS_CONTROLS_LINK_LISTENER_H_ -#define VIEWS_CONTROLS_LINK_LISTENER_H_ -#pragma once - -namespace views { - -class Link; - -// An interface implemented by an object to let it know that a link was clicked. -class LinkListener { - public: - virtual void LinkClicked(Link* source, int event_flags) = 0; - - protected: - virtual ~LinkListener() {} -}; - -} // namespace views - -#endif // VIEWS_CONTROLS_LINK_LISTENER_H_ diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc index 4926198..0da57c1 100644 --- a/views/controls/message_box_view.cc +++ b/views/controls/message_box_view.cc @@ -12,13 +12,13 @@ #include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/message_box_flags.h" #include "ui/views/controls/button/checkbox.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/layout/grid_layout.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/widget/widget.h" #include "ui/views/window/client_view.h" #include "views/controls/image_view.h" -#include "views/controls/label.h" #include "views/views_delegate.h" const int kDefaultMessageWidth = 320; diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc index 430fdbf..739a374 100644 --- a/views/view_text_utils.cc +++ b/views/view_text_utils.cc @@ -12,8 +12,8 @@ #include "ui/gfx/font.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" -#include "views/controls/label.h" -#include "views/controls/link.h" +#include "ui/views/controls/label.h" +#include "ui/views/controls/link.h" namespace view_text_utils { diff --git a/views/views.gyp b/views/views.gyp index d9e4112..841adb2 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -56,11 +56,6 @@ 'controls/focusable_border.h', 'controls/image_view.cc', 'controls/image_view.h', - 'controls/label.cc', - 'controls/label.h', - 'controls/link.cc', - 'controls/link.h', - 'controls/link_listener.h', 'controls/message_box_view.cc', 'controls/message_box_view.h', 'controls/native_control.cc', @@ -155,6 +150,11 @@ '../ui/views/controls/combobox/native_combobox_win.cc', '../ui/views/controls/combobox/native_combobox_win.h', '../ui/views/controls/combobox/native_combobox_wrapper.h', + '../ui/views/controls/label.cc', + '../ui/views/controls/label.h', + '../ui/views/controls/link.cc', + '../ui/views/controls/link.h', + '../ui/views/controls/link_listener.h', '../ui/views/controls/menu/menu.cc', '../ui/views/controls/menu/menu.h', '../ui/views/controls/menu/menu_2.cc', @@ -510,6 +510,7 @@ '../ui/views/bubble/bubble_delegate_unittest.cc', '../ui/views/bubble/bubble_frame_view_unittest.cc', '../ui/views/controls/combobox/native_combobox_views_unittest.cc', + '../ui/views/controls/label_unittest.cc', '../ui/views/controls/menu/menu_model_adapter_unittest.cc', '../ui/views/controls/scrollbar/scrollbar_unittest.cc', '../ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc', @@ -537,7 +538,6 @@ '../ui/views/widget/native_widget_win_unittest.cc', '../ui/views/widget/widget_unittest.cc', 'accessible_pane_view_unittest.cc', - 'controls/label_unittest.cc', 'controls/progress_bar_unittest.cc', 'controls/single_split_view_unittest.cc', 'run_all_unittests.cc', -- cgit v1.1