diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-01-25 11:39:07 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> | 2016-01-25 15:20:42 +0000 |
commit | 6c91641271e536ffaa88a1dff5127e42ee99a91e (patch) | |
tree | 703d9dd49602377ddc90cbf886aad37913f2496b /chromium/ui/base | |
parent | b145b7fafd36f0c260d6a768c81fc14e32578099 (diff) | |
download | qtwebengine-chromium-6c91641271e536ffaa88a1dff5127e42ee99a91e.tar.gz |
BASELINE: Update Chromium to 49.0.2623.23
Also adds missing printing sources.
Change-Id: I3726b8f0c7d6751c9fc846096c571fadca7108cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'chromium/ui/base')
247 files changed, 2707 insertions, 972 deletions
diff --git a/chromium/ui/base/BUILD.gn b/chromium/ui/base/BUILD.gn index 6fad1dcdb19..6190b065df1 100644 --- a/chromium/ui/base/BUILD.gn +++ b/chromium/ui/base/BUILD.gn @@ -125,12 +125,6 @@ component("base") { "dragdrop/os_exchange_data_provider_win.cc", "dragdrop/os_exchange_data_provider_win.h", "hit_test.h", - "idle/idle.cc", - "idle/idle.h", - "idle/idle_chromeos.cc", - "idle/idle_linux.cc", - "idle/idle_mac.mm", - "idle/idle_win.cc", "ios/cru_context_menu_controller.h", "ios/cru_context_menu_controller.mm", "ios/cru_context_menu_holder.h", @@ -293,6 +287,13 @@ component("base") { "dragdrop/drag_utils.h", "dragdrop/file_info.cc", "dragdrop/file_info.h", + "idle/idle.cc", + "idle/idle.h", + "idle/idle_android.cc", + "idle/idle_chromeos.cc", + "idle/idle_linux.cc", + "idle/idle_mac.mm", + "idle/idle_win.cc", "text/bytes_formatting.cc", "text/bytes_formatting.h", ] @@ -319,15 +320,15 @@ component("base") { public_deps = [ "//base", "//skia", - "//ui/events/platform", "//ui/events:events_base", + "//ui/events/platform", "//ui/gfx", "//ui/gfx/geometry", ] deps = [ - "//base/third_party/dynamic_annotations", "//base:base_static", "//base:i18n", + "//base/third_party/dynamic_annotations", "//net", "//third_party/icu", "//ui/events", @@ -408,7 +409,7 @@ component("base") { configs += [ "//build/config/linux:glib" ] } - if ((is_linux && !is_chromeos) || is_chromeos) { + if (is_linux) { if (!toolkit_views && !use_aura) { sources -= [ "dragdrop/drag_utils.cc", @@ -550,6 +551,9 @@ component("base") { "default_theme_provider.cc", "dragdrop/drag_utils.cc", "dragdrop/drag_utils.h", + "idle/idle.cc", + "idle/idle.h", + "idle/idle_android.cc", "l10n/l10n_font_util.cc", "models/button_menu_item_model.cc", "models/dialog_model.cc", @@ -570,11 +574,7 @@ component("base") { } if (is_android || is_ios) { - sources -= [ - "device_form_factor_desktop.cc", - "idle/idle.cc", - "idle/idle.h", - ] + sources -= [ "device_form_factor_desktop.cc" ] } } @@ -604,6 +604,13 @@ source_set("test_support") { "test/windowed_nsnotification_observer.h", "test/windowed_nsnotification_observer.mm", ] + } else { + sources += [ + "test/ios/keyboard_appearance_listener.h", + "test/ios/keyboard_appearance_listener.mm", + "test/ios/ui_view_test_utils.h", + "test/ios/ui_view_test_utils.mm", + ] } public_deps = [ @@ -611,9 +618,11 @@ source_set("test_support") { ] deps = [ "//base", + "//base/test:test_config", "//skia", "//testing/gtest", "//ui/events:events_base", + "//ui/events:test_support", "//ui/gfx", "//ui/gfx/geometry", ] @@ -731,7 +740,7 @@ test("ui_base_unittests") { sources += [ "ime/candidate_window_unittest.cc", "ime/chromeos/character_composer_unittest.cc", - "ime/chromeos/composition_text_chromeos_unittest.cc", + "ime/composition_text_unittest.cc", "ime/input_method_base_unittest.cc", "ime/input_method_chromeos_unittest.cc", "ime/remote_input_method_win_unittest.cc", @@ -741,6 +750,9 @@ test("ui_base_unittests") { if (is_linux && use_aura && !is_chromeos) { sources += [ "ime/input_method_auralinux_unittest.cc" ] } + if (is_mac) { + sources += [ "resource/resource_bundle_mac_unittest.mm" ] + } if (use_x11) { sources += [ "ime/composition_text_util_pango_unittest.cc" ] } @@ -805,7 +817,10 @@ test("ui_base_unittests") { } if (is_android) { - apk_deps = [ "//chrome:resources" ] + deps += [ + "//chrome:resources", + "//ui/android:ui_java", + ] isolate_file = "ui_base_unittests.isolate" } diff --git a/chromium/ui/base/accelerators/accelerator.cc b/chromium/ui/base/accelerators/accelerator.cc index bda48b3a269..fa166bdf009 100644 --- a/chromium/ui/base/accelerators/accelerator.cc +++ b/chromium/ui/base/accelerators/accelerator.cc @@ -4,18 +4,21 @@ #include "ui/base/accelerators/accelerator.h" -#if defined(OS_WIN) -#include <windows.h> -#endif +#include <stdint.h> #include "base/i18n/rtl.h" #include "base/logging.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" #include "ui/base/l10n/l10n_util.h" #include "ui/events/event.h" #include "ui/strings/grit/ui_strings.h" +#if defined(OS_WIN) +#include <windows.h> +#endif + #if !defined(OS_WIN) && (defined(USE_AURA) || defined(OS_MACOSX)) #include "ui/events/keycodes/keyboard_code_conversion.h" #endif @@ -46,8 +49,8 @@ Accelerator::Accelerator(KeyboardCode keycode, int modifiers) Accelerator::Accelerator(const KeyEvent& key_event) : key_code_(key_event.key_code()), type_(key_event.type()), - modifiers_(key_event.flags() & kEventFlagsMask), - is_repeat_(key_event.IsRepeat()) { + modifiers_(MaskOutKeyEventFlags(key_event.flags())), + is_repeat_(key_event.is_repeat()) { } Accelerator::Accelerator(const Accelerator& accelerator) { @@ -62,6 +65,11 @@ Accelerator::Accelerator(const Accelerator& accelerator) { Accelerator::~Accelerator() { } +// static +int Accelerator::MaskOutKeyEventFlags(int flags) { + return flags & kEventFlagsMask; +} + Accelerator& Accelerator::operator=(const Accelerator& accelerator) { if (this != &accelerator) { key_code_ = accelerator.key_code_; @@ -212,7 +220,7 @@ base::string16 Accelerator::GetShortcutText() const { key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); shortcut += key; #elif defined(USE_AURA) || defined(OS_MACOSX) - const uint16 c = DomCodeToUsLayoutCharacter( + const uint16_t c = DomCodeToUsLayoutCharacter( UsLayoutKeyboardCodeToDomCode(key_code_), false); if (c != 0) shortcut += diff --git a/chromium/ui/base/accelerators/accelerator.h b/chromium/ui/base/accelerators/accelerator.h index b41d9ac19eb..0a02e39d4cc 100644 --- a/chromium/ui/base/accelerators/accelerator.h +++ b/chromium/ui/base/accelerators/accelerator.h @@ -11,6 +11,8 @@ #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_H_ #define UI_BASE_ACCELERATORS_ACCELERATOR_H_ +#include <utility> + #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "ui/base/accelerators/platform_accelerator.h" @@ -33,6 +35,10 @@ class UI_BASE_EXPORT Accelerator { Accelerator(const Accelerator& accelerator); ~Accelerator(); + // Masks out all the non-modifiers KeyEvent |flags| and returns only the + // available modifier ones. + static int MaskOutKeyEventFlags(int flags); + Accelerator& operator=(const Accelerator& accelerator); // Define the < operator so that the KeyboardShortcut can be used as a key in @@ -62,7 +68,7 @@ class UI_BASE_EXPORT Accelerator { base::string16 GetShortcutText() const; void set_platform_accelerator(scoped_ptr<PlatformAccelerator> p) { - platform_accelerator_ = p.Pass(); + platform_accelerator_ = std::move(p); } // This class keeps ownership of the returned object. diff --git a/chromium/ui/base/accelerators/accelerator_history.h b/chromium/ui/base/accelerators/accelerator_history.h index 435e75274f2..22aaf1fcc8d 100644 --- a/chromium/ui/base/accelerators/accelerator_history.h +++ b/chromium/ui/base/accelerators/accelerator_history.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ #define UI_BASE_ACCELERATORS_ACCELERATOR_HISTORY_H_ +#include "base/macros.h" #include "base/memory/singleton.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/accelerators/accelerator_manager.h b/chromium/ui/base/accelerators/accelerator_manager.h index 8398c8f7404..905a8c9da9e 100644 --- a/chromium/ui/base/accelerators/accelerator_manager.h +++ b/chromium/ui/base/accelerators/accelerator_manager.h @@ -9,7 +9,7 @@ #include <map> #include <utility> -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/ui_base_export.h" #include "ui/events/event_constants.h" diff --git a/chromium/ui/base/accelerators/accelerator_manager_unittest.cc b/chromium/ui/base/accelerators/accelerator_manager_unittest.cc index 1f8db027b13..0236d567d93 100644 --- a/chromium/ui/base/accelerators/accelerator_manager_unittest.cc +++ b/chromium/ui/base/accelerators/accelerator_manager_unittest.cc @@ -5,6 +5,7 @@ #include "ui/base/accelerators/accelerator_manager.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/events/event_constants.h" #include "ui/events/keycodes/keyboard_codes.h" diff --git a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.cc b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.cc index 0a00f82e094..1213ec1dc7a 100644 --- a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.cc +++ b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.cc @@ -4,6 +4,8 @@ #include "ui/base/accelerators/menu_label_accelerator_util_linux.h" +#include <stddef.h> + #include "base/strings/string_util.h" namespace { diff --git a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux_unittest.cc b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux_unittest.cc index 0811e2b8aac..d704ef5ce51 100644 --- a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux_unittest.cc +++ b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux_unittest.cc @@ -4,7 +4,9 @@ #include "ui/base/accelerators/menu_label_accelerator_util_linux.h" -#include "base/basictypes.h" +#include <stddef.h> + +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace ui { diff --git a/chromium/ui/base/accelerators/platform_accelerator_cocoa.h b/chromium/ui/base/accelerators/platform_accelerator_cocoa.h index c6fed1d73b3..5685f5fee15 100644 --- a/chromium/ui/base/accelerators/platform_accelerator_cocoa.h +++ b/chromium/ui/base/accelerators/platform_accelerator_cocoa.h @@ -8,6 +8,7 @@ #include <Foundation/Foundation.h> #include "base/mac/scoped_nsobject.h" +#include "base/macros.h" #include "ui/base/accelerators/platform_accelerator.h" namespace ui { diff --git a/chromium/ui/base/android/OWNERS b/chromium/ui/base/android/OWNERS index 672fc82700c..bb2905fdd5b 100644 --- a/chromium/ui/base/android/OWNERS +++ b/chromium/ui/base/android/OWNERS @@ -1,3 +1,2 @@ -jdduke@chromium.org newt@chromium.org tedchoc@chromium.org diff --git a/chromium/ui/base/clipboard/clipboard.h b/chromium/ui/base/clipboard/clipboard.h index af8f439ce1e..40af4df4f2f 100644 --- a/chromium/ui/base/clipboard/clipboard.h +++ b/chromium/ui/base/clipboard/clipboard.h @@ -5,17 +5,22 @@ #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ +#include <stddef.h> +#include <stdint.h> + #include <map> #include <string> #include <vector> #include "base/compiler_specific.h" #include "base/lazy_instance.h" +#include "base/macros.h" #include "base/process/process.h" #include "base/strings/string16.h" #include "base/synchronization/lock.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_checker.h" +#include "build/build_config.h" #include "ui/base/clipboard/clipboard_types.h" #include "ui/base/ui_base_export.h" @@ -112,7 +117,7 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { // Copyable and assignable, since this is essentially an opaque value type. }; - static bool IsSupportedClipboardType(int32 type) { + static bool IsSupportedClipboardType(int32_t type) { switch (type) { case CLIPBOARD_TYPE_COPY_PASTE: return true; @@ -124,7 +129,7 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { return false; } - static ClipboardType FromInt(int32 type) { + static ClipboardType FromInt(int32_t type) { return static_cast<ClipboardType>(type); } @@ -148,7 +153,7 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { // Returns a sequence number which uniquely identifies clipboard state. // This can be used to version the data on the clipboard and determine // whether it has changed. - virtual uint64 GetSequenceNumber(ClipboardType type) const = 0; + virtual uint64_t GetSequenceNumber(ClipboardType type) const = 0; // Tests whether the clipboard contains a certain format virtual bool IsFormatAvailable(const FormatType& format, @@ -174,8 +179,8 @@ class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { virtual void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const = 0; + uint32_t* fragment_start, + uint32_t* fragment_end) const = 0; // Reads RTF from the clipboard, if available. Stores the result as a byte // vector. diff --git a/chromium/ui/base/clipboard/clipboard_android.cc b/chromium/ui/base/clipboard/clipboard_android.cc index 1a0d0f93724..47465b04813 100644 --- a/chromium/ui/base/clipboard/clipboard_android.cc +++ b/chromium/ui/base/clipboard/clipboard_android.cc @@ -4,6 +4,7 @@ #include "ui/base/clipboard/clipboard_android.h" +#include "base/android/context_utils.h" #include "base/android/jni_string.h" #include "base/lazy_instance.h" #include "base/stl_util.h" @@ -281,7 +282,7 @@ ClipboardAndroid::~ClipboardAndroid() { DCHECK(CalledOnValidThread()); } -uint64 ClipboardAndroid::GetSequenceNumber(ClipboardType /* type */) const { +uint64_t ClipboardAndroid::GetSequenceNumber(ClipboardType /* type */) const { DCHECK(CalledOnValidThread()); // TODO: implement this. For now this interface will advertise // that the clipboard never changes. That's fine as long as we @@ -351,8 +352,8 @@ void ClipboardAndroid::ReadAsciiText(ClipboardType type, void ClipboardAndroid::ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); if (src_url) @@ -362,7 +363,7 @@ void ClipboardAndroid::ReadHTML(ClipboardType type, *markup = base::UTF8ToUTF16(input); *fragment_start = 0; - *fragment_end = static_cast<uint32>(markup->length()); + *fragment_end = static_cast<uint32_t>(markup->length()); } void ClipboardAndroid::ReadRTF(ClipboardType type, std::string* result) const { diff --git a/chromium/ui/base/clipboard/clipboard_android.h b/chromium/ui/base/clipboard/clipboard_android.h index 660475a9828..2ec2f46eb9e 100644 --- a/chromium/ui/base/clipboard/clipboard_android.h +++ b/chromium/ui/base/clipboard/clipboard_android.h @@ -8,6 +8,10 @@ #include "ui/base/clipboard/clipboard.h" #include <jni.h> +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" namespace ui { @@ -21,7 +25,7 @@ class ClipboardAndroid : public Clipboard { ~ClipboardAndroid() override; // Clipboard overrides: - uint64 GetSequenceNumber(ClipboardType type) const override; + uint64_t GetSequenceNumber(ClipboardType type) const override; bool IsFormatAvailable(const FormatType& format, ClipboardType type) const override; void Clear(ClipboardType type) override; @@ -33,8 +37,8 @@ class ClipboardAndroid : public Clipboard { void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const override; + uint32_t* fragment_start, + uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/clipboard_android_unittest.cc b/chromium/ui/base/clipboard/clipboard_android_unittest.cc index 41ce5526c75..b6744a2b36e 100644 --- a/chromium/ui/base/clipboard/clipboard_android_unittest.cc +++ b/chromium/ui/base/clipboard/clipboard_android_unittest.cc @@ -4,6 +4,7 @@ #include "ui/base/clipboard/clipboard_android.h" +#include "base/android/context_utils.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/ui/base/clipboard/clipboard_aura.cc b/chromium/ui/base/clipboard/clipboard_aura.cc index e682392436f..11bdd54cf93 100644 --- a/chromium/ui/base/clipboard/clipboard_aura.cc +++ b/chromium/ui/base/clipboard/clipboard_aura.cc @@ -4,11 +4,14 @@ #include "ui/base/clipboard/clipboard_aura.h" +#include <stdint.h> + +#include <limits> #include <list> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" #include "base/strings/utf_string_conversions.h" @@ -210,8 +213,8 @@ class AuraClipboard { // Reads HTML from the data at the top of clipboard stack. void ReadHTML(base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { markup->clear(); if (src_url) src_url->clear(); @@ -226,8 +229,8 @@ class AuraClipboard { *src_url = data->url(); *fragment_start = 0; - DCHECK_LE(markup->length(), kuint32max); - *fragment_end = static_cast<uint32>(markup->length()); + DCHECK_LE(markup->length(), std::numeric_limits<uint32_t>::max()); + *fragment_end = static_cast<uint32_t>(markup->length()); } // Reads RTF from the data at the top of clipboard stack. @@ -528,7 +531,7 @@ ClipboardAura::~ClipboardAura() { DeleteClipboard(); } -uint64 ClipboardAura::GetSequenceNumber(ClipboardType type) const { +uint64_t ClipboardAura::GetSequenceNumber(ClipboardType type) const { DCHECK(CalledOnValidThread()); return GetClipboard()->sequence_number(); } @@ -605,8 +608,8 @@ void ClipboardAura::ReadAsciiText(ClipboardType type, void ClipboardAura::ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); } diff --git a/chromium/ui/base/clipboard/clipboard_aura.h b/chromium/ui/base/clipboard/clipboard_aura.h index e5fbc3407fc..e13f17760f5 100644 --- a/chromium/ui/base/clipboard/clipboard_aura.h +++ b/chromium/ui/base/clipboard/clipboard_aura.h @@ -5,6 +5,10 @@ #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_AURA_H_ #define UI_BASE_CLIPBOARD_CLIPBOARD_AURA_H_ +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "ui/base/clipboard/clipboard.h" namespace ui { @@ -17,7 +21,7 @@ class ClipboardAura : public Clipboard { ~ClipboardAura() override; // Clipboard overrides: - uint64 GetSequenceNumber(ClipboardType type) const override; + uint64_t GetSequenceNumber(ClipboardType type) const override; bool IsFormatAvailable(const FormatType& format, ClipboardType type) const override; void Clear(ClipboardType type) override; @@ -29,8 +33,8 @@ class ClipboardAura : public Clipboard { void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const override; + uint32_t* fragment_start, + uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/clipboard_aurax11.cc b/chromium/ui/base/clipboard/clipboard_aurax11.cc index b9b53f18f36..29061eb928b 100644 --- a/chromium/ui/base/clipboard/clipboard_aurax11.cc +++ b/chromium/ui/base/clipboard/clipboard_aurax11.cc @@ -4,14 +4,17 @@ #include "ui/base/clipboard/clipboard_aurax11.h" +#include <stdint.h> #include <X11/extensions/Xfixes.h> #include <X11/Xatom.h> + +#include <limits> #include <list> #include <set> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" @@ -65,10 +68,10 @@ class SelectionChangeObserver : public ui::PlatformEventObserver { public: static SelectionChangeObserver* GetInstance(); - uint64 clipboard_sequence_number() const { + uint64_t clipboard_sequence_number() const { return clipboard_sequence_number_; } - uint64 primary_sequence_number() const { return primary_sequence_number_; } + uint64_t primary_sequence_number() const { return primary_sequence_number_; } private: friend struct base::DefaultSingletonTraits<SelectionChangeObserver>; @@ -82,8 +85,8 @@ class SelectionChangeObserver : public ui::PlatformEventObserver { int event_base_; Atom clipboard_atom_; - uint64 clipboard_sequence_number_; - uint64 primary_sequence_number_; + uint64_t clipboard_sequence_number_; + uint64_t primary_sequence_number_; DISALLOW_COPY_AND_ASSIGN(SelectionChangeObserver); }; @@ -670,7 +673,7 @@ ClipboardAuraX11::~ClipboardAuraX11() { aurax11_details_->StoreCopyPasteDataAndWait(); } -uint64 ClipboardAuraX11::GetSequenceNumber(ClipboardType type) const { +uint64_t ClipboardAuraX11::GetSequenceNumber(ClipboardType type) const { DCHECK(CalledOnValidThread()); if (type == CLIPBOARD_TYPE_COPY_PASTE) return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); @@ -753,8 +756,8 @@ void ClipboardAuraX11::ReadAsciiText(ClipboardType type, void ClipboardAuraX11::ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); markup->clear(); if (src_url) @@ -768,8 +771,8 @@ void ClipboardAuraX11::ReadHTML(ClipboardType type, *markup = data.GetHtml(); *fragment_start = 0; - DCHECK(markup->length() <= kuint32max); - *fragment_end = static_cast<uint32>(markup->length()); + DCHECK(markup->length() <= std::numeric_limits<uint32_t>::max()); + *fragment_end = static_cast<uint32_t>(markup->length()); } } diff --git a/chromium/ui/base/clipboard/clipboard_aurax11.h b/chromium/ui/base/clipboard/clipboard_aurax11.h index 1b30a3b0daf..9a735d7504f 100644 --- a/chromium/ui/base/clipboard/clipboard_aurax11.h +++ b/chromium/ui/base/clipboard/clipboard_aurax11.h @@ -7,6 +7,10 @@ #include "ui/base/clipboard/clipboard.h" +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "base/memory/scoped_ptr.h" namespace ui { @@ -19,7 +23,7 @@ class ClipboardAuraX11 : public Clipboard { ~ClipboardAuraX11() override; // Clipboard overrides: - uint64 GetSequenceNumber(ClipboardType type) const override; + uint64_t GetSequenceNumber(ClipboardType type) const override; bool IsFormatAvailable(const FormatType& format, ClipboardType type) const override; void Clear(ClipboardType type) override; @@ -31,8 +35,8 @@ class ClipboardAuraX11 : public Clipboard { void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const override; + uint32_t* fragment_start, + uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/clipboard_mac.h b/chromium/ui/base/clipboard/clipboard_mac.h index d6a1d439be6..3a4ef4a40e1 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.h +++ b/chromium/ui/base/clipboard/clipboard_mac.h @@ -5,6 +5,10 @@ #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_MAC_H_ #define UI_BASE_CLIPBOARD_CLIPBOARD_MAC_H_ +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "ui/base/clipboard/clipboard.h" namespace ui { @@ -17,7 +21,7 @@ class ClipboardMac : public Clipboard { ~ClipboardMac() override; // Clipboard overrides: - uint64 GetSequenceNumber(ClipboardType type) const override; + uint64_t GetSequenceNumber(ClipboardType type) const override; bool IsFormatAvailable(const FormatType& format, ClipboardType type) const override; void Clear(ClipboardType type) override; @@ -29,8 +33,8 @@ class ClipboardMac : public Clipboard { void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const override; + uint32_t* fragment_start, + uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/clipboard_mac.mm b/chromium/ui/base/clipboard/clipboard_mac.mm index 62331947ddf..eb4fc21b11a 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_mac.mm @@ -5,8 +5,10 @@ #include "ui/base/clipboard/clipboard_mac.h" #import <Cocoa/Cocoa.h> +#include <stdint.h> + +#include <limits> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/logging.h" #include "base/mac/mac_util.h" @@ -183,7 +185,7 @@ ClipboardMac::~ClipboardMac() { DCHECK(CalledOnValidThread()); } -uint64 ClipboardMac::GetSequenceNumber(ClipboardType type) const { +uint64_t ClipboardMac::GetSequenceNumber(ClipboardType type) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); @@ -264,8 +266,8 @@ void ClipboardMac::ReadAsciiText(ClipboardType type, void ClipboardMac::ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); @@ -288,8 +290,8 @@ void ClipboardMac::ReadHTML(ClipboardType type, } *fragment_start = 0; - DCHECK(markup->length() <= kuint32max); - *fragment_end = static_cast<uint32>(markup->length()); + DCHECK(markup->length() <= std::numeric_limits<uint32_t>::max()); + *fragment_end = static_cast<uint32_t>(markup->length()); } void ClipboardMac::ReadRTF(ClipboardType type, std::string* result) const { @@ -307,14 +309,27 @@ SkBitmap ClipboardMac::ReadImage(ClipboardType type) const { // may throw, and that exception will leak. Prevent a crash in that case; // a blank image is better. base::scoped_nsobject<NSImage> image; + NSPasteboard* pb = GetPasteboard(); @try { - image.reset([[NSImage alloc] initWithPasteboard:GetPasteboard()]); + if ([[pb types] containsObject:NSFilenamesPboardType]) { + // -[NSImage initWithPasteboard:] gets confused with copies of a single + // file from the Finder, so extract the path ourselves. + // http://crbug.com/553686 + NSArray* paths = [pb propertyListForType:NSFilenamesPboardType]; + if ([paths count]) { + // If N number of files are selected from finder, choose the last one. + image.reset([[NSImage alloc] + initWithContentsOfURL:[NSURL fileURLWithPath:[paths lastObject]]]); + } + } else { + image.reset([[NSImage alloc] initWithPasteboard:pb]); + } } @catch (id exception) { } SkBitmap bitmap; if (image.get()) { - bitmap = gfx::NSImageToSkBitmapWithColorSpace( + bitmap = skia::NSImageToSkBitmapWithColorSpace( image.get(), /*is_opaque=*/ false, base::mac::GetSystemColorSpace()); } return bitmap; @@ -425,7 +440,7 @@ void ClipboardMac::WriteBookmark(const char* title_data, } void ClipboardMac::WriteBitmap(const SkBitmap& bitmap) { - NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( + NSImage* image = skia::SkBitmapToNSImageWithColorSpace( bitmap, base::mac::GetSystemColorSpace()); // An API to ask the NSImage to write itself to the clipboard comes in 10.6 :( // For now, spit out the image as a TIFF. diff --git a/chromium/ui/base/clipboard/clipboard_test_template.h b/chromium/ui/base/clipboard/clipboard_test_template.h index 2b298da68d9..122fb4e196d 100644 --- a/chromium/ui/base/clipboard/clipboard_test_template.h +++ b/chromium/ui/base/clipboard/clipboard_test_template.h @@ -14,9 +14,10 @@ #include "build/build_config.h" +#include <stdint.h> + #include <string> -#include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/pickle.h" @@ -143,8 +144,8 @@ TYPED_TEST(ClipboardTest, HTMLTest) { Contains(ASCIIToUTF16(Clipboard::kMimeTypeHTML))); EXPECT_TRUE(this->clipboard().IsFormatAvailable( Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, &fragment_start, &fragment_end); EXPECT_LE(markup.size(), fragment_end - fragment_start); @@ -214,8 +215,8 @@ TYPED_TEST(ClipboardTest, MultipleBufferTest) { EXPECT_EQ(text, text_result); base::string16 markup_result; - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_SELECTION, &markup_result, &url_result, &fragment_start, &fragment_end); EXPECT_LE(markup.size(), fragment_end - fragment_start); @@ -240,8 +241,8 @@ TYPED_TEST(ClipboardTest, TrickyHTMLTest) { Contains(ASCIIToUTF16(Clipboard::kMimeTypeHTML))); EXPECT_TRUE(this->clipboard().IsFormatAvailable( Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, &fragment_start, &fragment_end); EXPECT_LE(markup.size(), fragment_end - fragment_start); @@ -270,8 +271,8 @@ TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { Contains(ASCIIToUTF16(Clipboard::kMimeTypeHTML))); EXPECT_TRUE(this->clipboard().IsFormatAvailable( Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, &fragment_start, &fragment_end); EXPECT_LE(markup.size(), fragment_end - fragment_start); @@ -323,8 +324,8 @@ TYPED_TEST(ClipboardTest, MultiFormatTest) { Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); EXPECT_TRUE(this->clipboard().IsFormatAvailable( Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, &url_result, &fragment_start, &fragment_end); EXPECT_LE(markup.size(), fragment_end - fragment_start); @@ -374,7 +375,7 @@ TYPED_TEST(ClipboardTest, URLTest) { static void TestBitmapWrite(Clipboard* clipboard, const gfx::Size& size, - const uint32* bitmap_data) { + const uint32_t* bitmap_data) { { ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); SkBitmap bitmap; @@ -391,7 +392,7 @@ static void TestBitmapWrite(Clipboard* clipboard, EXPECT_EQ(size, gfx::Size(image.width(), image.height())); SkAutoLockPixels image_lock(image); for (int j = 0; j < image.height(); ++j) { - const uint32* row_address = image.getAddr32(0, j); + const uint32_t* row_address = image.getAddr32(0, j); for (int i = 0; i < image.width(); ++i) { int offset = i + j * image.width(); EXPECT_EQ(bitmap_data[offset], row_address[i]) << "i = " << i @@ -401,7 +402,7 @@ static void TestBitmapWrite(Clipboard* clipboard, } TYPED_TEST(ClipboardTest, SharedBitmapTest) { - const uint32 fake_bitmap_1[] = { + const uint32_t fake_bitmap_1[] = { 0x46061626, 0xf69f5988, 0x793f2937, 0xfa55b986, 0x78772152, 0x87692a30, 0x36322a25, 0x4320401b, 0x91848c21, 0xc3177b3c, 0x6946155c, 0x64171952, @@ -411,7 +412,7 @@ TYPED_TEST(ClipboardTest, SharedBitmapTest) { TestBitmapWrite(&this->clipboard(), gfx::Size(4, 3), fake_bitmap_1); } - const uint32 fake_bitmap_2[] = { + const uint32_t fake_bitmap_2[] = { 0x46061626, 0xf69f5988, 0x793f2937, 0xfa55b986, 0x78772152, 0x87692a30, @@ -524,8 +525,8 @@ TYPED_TEST(ClipboardTest, HyperlinkTest) { EXPECT_TRUE(this->clipboard().IsFormatAvailable( Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); - uint32 fragment_start; - uint32 fragment_end; + uint32_t fragment_start; + uint32_t fragment_end; this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result, &url_result, &fragment_start, &fragment_end); EXPECT_EQ(kExpectedHtml, @@ -615,7 +616,7 @@ TYPED_TEST(ClipboardTest, WriteEverything) { // written to. // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION. TYPED_TEST(ClipboardTest, GetSequenceNumber) { - const uint64 first_sequence_number = + const uint64_t first_sequence_number = this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); { @@ -627,7 +628,7 @@ TYPED_TEST(ClipboardTest, GetSequenceNumber) { // the message loop to make sure we get the notification. base::RunLoop().RunUntilIdle(); - const uint64 second_sequence_number = + const uint64_t second_sequence_number = this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); EXPECT_NE(first_sequence_number, second_sequence_number); diff --git a/chromium/ui/base/clipboard/clipboard_util_win.cc b/chromium/ui/base/clipboard/clipboard_util_win.cc index c0c05b054bb..9f236359693 100644 --- a/chromium/ui/base/clipboard/clipboard_util_win.cc +++ b/chromium/ui/base/clipboard/clipboard_util_win.cc @@ -8,9 +8,9 @@ #include <shlwapi.h> #include <wininet.h> // For INTERNET_MAX_URL_LENGTH. -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/logging.h" +#include "base/macros.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -446,7 +446,7 @@ void ClipboardUtil::CFHtmlToHtml(const std::string& cf_html, fragment_start != std::string::npos && fragment_end != std::string::npos) { *html = cf_html.substr(fragment_start, fragment_end - fragment_start); - base::TrimWhitespace(*html, base::TRIM_ALL, html); + base::TrimWhitespaceASCII(*html, base::TRIM_ALL, html); } } @@ -464,7 +464,7 @@ void ClipboardUtil::CFHtmlExtractMetadata(const std::string& cf_html, size_t src_start = line_start + src_url_str.length(); if (src_end != std::string::npos && src_start != std::string::npos) { *base_url = cf_html.substr(src_start, src_end - src_start); - base::TrimWhitespace(*base_url, base::TRIM_ALL, base_url); + base::TrimWhitespaceASCII(*base_url, base::TRIM_ALL, base_url); } } } diff --git a/chromium/ui/base/clipboard/clipboard_util_win.h b/chromium/ui/base/clipboard/clipboard_util_win.h index c2171da5f16..c87091606c8 100644 --- a/chromium/ui/base/clipboard/clipboard_util_win.h +++ b/chromium/ui/base/clipboard/clipboard_util_win.h @@ -8,6 +8,7 @@ #define UI_BASE_CLIPBOARD_CLIPBOARD_UTIL_WIN_H_ #include <shlobj.h> +#include <stddef.h> #include <map> #include <string> #include <vector> diff --git a/chromium/ui/base/clipboard/clipboard_win.cc b/chromium/ui/base/clipboard/clipboard_win.cc index 2743755dfd4..712b7e8be14 100644 --- a/chromium/ui/base/clipboard/clipboard_win.cc +++ b/chromium/ui/base/clipboard/clipboard_win.cc @@ -10,11 +10,11 @@ #include <shellapi.h> #include <shlobj.h> -#include "base/basictypes.h" #include "base/bind.h" #include "base/files/file_path.h" #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/numerics/safe_conversions.h" #include "base/stl_util.h" @@ -160,10 +160,10 @@ HGLOBAL CreateGlobalData(const std::basic_string<charT>& str) { return data; } -bool BitmapHasInvalidPremultipliedColors(const SkBitmap& bitmap) { - for (int x = 0; x < bitmap.width(); ++x) { - for (int y = 0; y < bitmap.height(); ++y) { - uint32_t pixel = *bitmap.getAddr32(x, y); +bool BitmapHasInvalidPremultipliedColors(const SkPixmap& pixmap) { + for (int x = 0; x < pixmap.width(); ++x) { + for (int y = 0; y < pixmap.height(); ++y) { + uint32_t pixel = *pixmap.addr32(x, y); if (SkColorGetR(pixel) > SkColorGetA(pixel) || SkColorGetG(pixel) > SkColorGetA(pixel) || SkColorGetB(pixel) > SkColorGetA(pixel)) @@ -173,10 +173,10 @@ bool BitmapHasInvalidPremultipliedColors(const SkBitmap& bitmap) { return false; } -void MakeBitmapOpaque(const SkBitmap& bitmap) { - for (int x = 0; x < bitmap.width(); ++x) { - for (int y = 0; y < bitmap.height(); ++y) { - *bitmap.getAddr32(x, y) = SkColorSetA(*bitmap.getAddr32(x, y), 0xFF); +void MakeBitmapOpaque(SkPixmap* pixmap) { + for (int x = 0; x < pixmap->width(); ++x) { + for (int y = 0; y < pixmap->height(); ++y) { + *pixmap->writable_addr32(x, y) = SkColorSetA(*pixmap->addr32(x, y), 0xFF); } } } @@ -418,7 +418,7 @@ ClipboardWin::ClipboardWin() { ClipboardWin::~ClipboardWin() { } -uint64 ClipboardWin::GetSequenceNumber(ClipboardType type) const { +uint64_t ClipboardWin::GetSequenceNumber(ClipboardType type) const { DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); return ::GetClipboardSequenceNumber(); } @@ -520,8 +520,8 @@ void ClipboardWin::ReadAsciiText(ClipboardType type, void ClipboardWin::ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const { + uint32_t* fragment_start, + uint32_t* fragment_end) const { DCHECK_EQ(type, CLIPBOARD_TYPE_COPY_PASTE); markup->clear(); @@ -565,8 +565,8 @@ void ClipboardWin::ReadHTML(ClipboardType type, offsets.push_back(end_index - html_start); markup->assign(base::UTF8ToUTF16AndAdjustOffsets(cf_html.data() + html_start, &offsets)); - *fragment_start = base::checked_cast<uint32>(offsets[0]); - *fragment_end = base::checked_cast<uint32>(offsets[1]); + *fragment_start = base::checked_cast<uint32_t>(offsets[0]); + *fragment_end = base::checked_cast<uint32_t>(offsets[1]); } void ClipboardWin::ReadRTF(ClipboardType type, std::string* result) const { @@ -631,14 +631,13 @@ SkBitmap ClipboardWin::ReadImage(ClipboardType type) const { // we assume the alpha channel contains garbage and force the bitmap to be // opaque as well. Note that this heuristic will fail on a transparent bitmap // containing only black pixels... - const SkBitmap& device_bitmap = - canvas.sk_canvas()->getDevice()->accessBitmap(true); + SkPixmap device_pixels; + skia::GetWritablePixels(canvas.sk_canvas(), &device_pixels); { - SkAutoLockPixels lock(device_bitmap); bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || - BitmapHasInvalidPremultipliedColors(device_bitmap); + BitmapHasInvalidPremultipliedColors(device_pixels); if (has_invalid_alpha_channel) { - MakeBitmapOpaque(device_bitmap); + MakeBitmapOpaque(&device_pixels); } } diff --git a/chromium/ui/base/clipboard/clipboard_win.h b/chromium/ui/base/clipboard/clipboard_win.h index 49ceb972f31..63bdfa114c5 100644 --- a/chromium/ui/base/clipboard/clipboard_win.h +++ b/chromium/ui/base/clipboard/clipboard_win.h @@ -7,6 +7,10 @@ #include "ui/base/clipboard/clipboard.h" +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "base/memory/scoped_ptr.h" namespace ui { @@ -19,7 +23,7 @@ class ClipboardWin : public Clipboard { ~ClipboardWin() override; // Clipboard overrides: - uint64 GetSequenceNumber(ClipboardType type) const override; + uint64_t GetSequenceNumber(ClipboardType type) const override; bool IsFormatAvailable(const FormatType& format, ClipboardType type) const override; void Clear(ClipboardType type) override; @@ -31,8 +35,8 @@ class ClipboardWin : public Clipboard { void ReadHTML(ClipboardType type, base::string16* markup, std::string* src_url, - uint32* fragment_start, - uint32* fragment_end) const override; + uint32_t* fragment_start, + uint32_t* fragment_end) const override; void ReadRTF(ClipboardType type, std::string* result) const override; SkBitmap ReadImage(ClipboardType type) const override; void ReadCustomData(ClipboardType clipboard_type, diff --git a/chromium/ui/base/clipboard/custom_data_helper.h b/chromium/ui/base/clipboard/custom_data_helper.h index c1778c73bf6..55a2b3bb22c 100644 --- a/chromium/ui/base/clipboard/custom_data_helper.h +++ b/chromium/ui/base/clipboard/custom_data_helper.h @@ -10,10 +10,13 @@ #ifndef UI_BASE_CLIPBOARD_CUSTOM_DATA_HELPER_H_ #define UI_BASE_CLIPBOARD_CUSTOM_DATA_HELPER_H_ +#include <stddef.h> + #include <map> #include <vector> #include "base/strings/string16.h" +#include "build/build_config.h" #include "ui/base/ui_base_export.h" namespace base { diff --git a/chromium/ui/base/clipboard/scoped_clipboard_writer.h b/chromium/ui/base/clipboard/scoped_clipboard_writer.h index 664dc2391de..a7e064561ca 100644 --- a/chromium/ui/base/clipboard/scoped_clipboard_writer.h +++ b/chromium/ui/base/clipboard/scoped_clipboard_writer.h @@ -13,6 +13,7 @@ #include <string> +#include "base/macros.h" #include "base/strings/string16.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard.h" diff --git a/chromium/ui/base/cocoa/base_view.h b/chromium/ui/base/cocoa/base_view.h index 642ada2011d..0675caeae63 100644 --- a/chromium/ui/base/cocoa/base_view.h +++ b/chromium/ui/base/cocoa/base_view.h @@ -8,6 +8,7 @@ #import <Cocoa/Cocoa.h> #include "base/mac/scoped_nsobject.h" +#include "base/mac/sdk_forward_declarations.h" #import "ui/base/cocoa/tracking_area.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/geometry/rect.h" @@ -28,15 +29,19 @@ UI_BASE_EXPORT ui::ScopedCrTrackingArea trackingArea_; BOOL dragging_; base::scoped_nsobject<NSEvent> pendingExitEvent_; + NSInteger pressureEventStage_; } -// Override these methods (mouseEvent, keyEvent) in a subclass. +// Override these methods (mouseEvent, keyEvent, forceTouchEvent) in a +// subclass. - (void)mouseEvent:(NSEvent *)theEvent; // keyEvent should return kEventHandled if it handled the event, or // kEventNotHandled if it should be forwarded to BaseView's super class. - (EventHandled)keyEvent:(NSEvent *)theEvent; +- (void)forceTouchEvent:(NSEvent*)theEvent; + // Useful rect conversions (doing coordinate flipping) - (gfx::Rect)flipNSRectToRect:(NSRect)rect; - (NSRect)flipRectToNSRect:(gfx::Rect)rect; diff --git a/chromium/ui/base/cocoa/base_view.mm b/chromium/ui/base/cocoa/base_view.mm index fdc58fcb0e3..9642fbe1a81 100644 --- a/chromium/ui/base/cocoa/base_view.mm +++ b/chromium/ui/base/cocoa/base_view.mm @@ -78,6 +78,10 @@ NSString* kSelectionDirection = @"Chromium.kSelectionDirection"; return kEventNotHandled; } +- (void)forceTouchEvent:(NSEvent*)theEvent { + // This method left intentionally blank. +} + - (void)mouseDown:(NSEvent*)theEvent { dragging_ = YES; [self mouseEvent:theEvent]; @@ -166,6 +170,19 @@ NSString* kSelectionDirection = @"Chromium.kSelectionDirection"; [super keyUp:theEvent]; } +- (void)pressureChangeWithEvent:(NSEvent*)theEvent { + NSInteger newStage = [theEvent stage]; + if (pressureEventStage_ == newStage) + return; + + // Call the force touch event when the stage reaches 2, which is the value + // for force touch. + if (newStage == 2) { + [self forceTouchEvent:theEvent]; + } + pressureEventStage_ = newStage; +} + - (void)flagsChanged:(NSEvent*)theEvent { if ([self keyEvent:theEvent] != kEventHandled) [super flagsChanged:theEvent]; diff --git a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm index 17cea548ad8..3618a1b9782 100644 --- a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm +++ b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm @@ -4,9 +4,12 @@ #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" +#include <stdint.h> + #include "base/files/file_path.h" #include "base/location.h" #import "base/mac/foundation_util.h" +#include "base/macros.h" #include "base/native_library.h" #include "ui/gfx/animation/tween.h" @@ -34,8 +37,8 @@ extern "C" { typedef float float32; -typedef int32 CGSWindow; -typedef int32 CGSConnection; +typedef int32_t CGSWindow; +typedef int32_t CGSConnection; typedef struct { float32 x; @@ -53,8 +56,8 @@ CGError CGSSetWindowTransform(const CGSConnection cid, CGAffineTransform transform); CGError CGSSetWindowWarp(const CGSConnection cid, const CGSWindow wid, - int32 w, - int32 h, + int32_t w, + int32_t h, CGPointWarp* mesh); CGError CGSSetWindowAlpha(const CGSConnection cid, const CGSWindow wid, diff --git a/chromium/ui/base/cocoa/controls/blue_label_button.mm b/chromium/ui/base/cocoa/controls/blue_label_button.mm index 319fff85a54..9d9b5805c9c 100644 --- a/chromium/ui/base/cocoa/controls/blue_label_button.mm +++ b/chromium/ui/base/cocoa/controls/blue_label_button.mm @@ -63,7 +63,7 @@ const SkColor kPressOuterRingColor = SkColorSetRGB(0x23, 0x52, 0xa2); base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); [shadow setShadowOffset:NSMakeSize(0, -1)]; [shadow setShadowBlurRadius:0]; - [shadow setShadowColor:gfx::SkColorToSRGBNSColor(kTextShadowColor)]; + [shadow setShadowColor:skia::SkColorToSRGBNSColor(kTextShadowColor)]; NSDictionary* buttonTextAttributes = @{ NSParagraphStyleAttributeName : buttonTextParagraphStyle, @@ -112,24 +112,24 @@ const SkColor kPressOuterRingColor = SkColorSetRGB(0x23, 0x52, 0xa2); frame.size.height -= 1; if (hoverState == kHoverStateMouseDown && [self isHighlighted]) { - centerColor = gfx::SkColorToSRGBNSColor(kPressedColor); - innerColor = gfx::SkColorToSRGBNSColor(kPressInnerRingColor); - outerColor = gfx::SkColorToSRGBNSColor(kPressOuterRingColor); + centerColor = skia::SkColorToSRGBNSColor(kPressedColor); + innerColor = skia::SkColorToSRGBNSColor(kPressInnerRingColor); + outerColor = skia::SkColorToSRGBNSColor(kPressOuterRingColor); } else { centerColor = hoverState == kHoverStateMouseOver ? - gfx::SkColorToSRGBNSColor(kHoverColor) : - gfx::SkColorToSRGBNSColor(kDefaultColor); + skia::SkColorToSRGBNSColor(kHoverColor) : + skia::SkColorToSRGBNSColor(kDefaultColor); innerColor = [self showsFirstResponder] ? - gfx::SkColorToSRGBNSColor(kFocusInnerRingColor) : - gfx::SkColorToSRGBNSColor(kInnerRingColor); - outerColor = gfx::SkColorToSRGBNSColor(kOuterRingColor); + skia::SkColorToSRGBNSColor(kFocusInnerRingColor) : + skia::SkColorToSRGBNSColor(kInnerRingColor); + outerColor = skia::SkColorToSRGBNSColor(kOuterRingColor); } { gfx::ScopedNSGraphicsContextSaveGState context; base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); [shadow setShadowOffset:NSMakeSize(0, -1)]; [shadow setShadowBlurRadius:1.0]; - [shadow setShadowColor:gfx::SkColorToSRGBNSColor(kShadowColor)]; + [shadow setShadowColor:skia::SkColorToSRGBNSColor(kShadowColor)]; [shadow set]; [outerColor set]; diff --git a/chromium/ui/base/cocoa/controls/blue_label_button_unittest.mm b/chromium/ui/base/cocoa/controls/blue_label_button_unittest.mm index 4118ca854f0..0427d9b064d 100644 --- a/chromium/ui/base/cocoa/controls/blue_label_button_unittest.mm +++ b/chromium/ui/base/cocoa/controls/blue_label_button_unittest.mm @@ -5,6 +5,7 @@ #import "ui/base/cocoa/controls/blue_label_button.h" #include "base/mac/scoped_nsobject.h" +#include "base/macros.h" #import "testing/gtest_mac.h" #import "ui/gfx/test/ui_cocoa_test_helper.h" diff --git a/chromium/ui/base/cocoa/controls/hover_image_menu_button_unittest.mm b/chromium/ui/base/cocoa/controls/hover_image_menu_button_unittest.mm index f873776c0c5..e137d55146d 100644 --- a/chromium/ui/base/cocoa/controls/hover_image_menu_button_unittest.mm +++ b/chromium/ui/base/cocoa/controls/hover_image_menu_button_unittest.mm @@ -5,8 +5,10 @@ #import "ui/base/cocoa/controls/hover_image_menu_button.h" #include "base/mac/foundation_util.h" +#include "base/macros.h" #import "testing/gtest_mac.h" #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h" +#include "ui/events/test/cocoa_test_event_utils.h" #import "ui/gfx/test/ui_cocoa_test_helper.h" namespace ui { @@ -157,13 +159,13 @@ TEST_F(HoverImageMenuButtonTest, SimulateMouseEnterExit) { EXPECT_FALSE([menu_button_ needsDisplay]); EXPECT_NSEQ(normal_, [[menu_button_ cell] imageToDraw]); - [menu_button_ mouseEntered:nil]; + [menu_button_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; EXPECT_TRUE([menu_button_ needsDisplay]); EXPECT_NSEQ(hovered_, [[menu_button_ cell] imageToDraw]); [menu_button_ display]; EXPECT_FALSE([menu_button_ needsDisplay]); - [menu_button_ mouseExited:nil]; + [menu_button_ mouseExited:cocoa_test_event_utils::ExitEvent()]; EXPECT_TRUE([menu_button_ needsDisplay]); EXPECT_NSEQ(normal_, [[menu_button_ cell] imageToDraw]); [menu_button_ display]; diff --git a/chromium/ui/base/cocoa/controls/hyperlink_button_cell.h b/chromium/ui/base/cocoa/controls/hyperlink_button_cell.h index 6e3b74d437b..f8753e48660 100644 --- a/chromium/ui/base/cocoa/controls/hyperlink_button_cell.h +++ b/chromium/ui/base/cocoa/controls/hyperlink_button_cell.h @@ -11,8 +11,8 @@ #include "ui/base/ui_base_export.h" // A HyperlinkButtonCell is used to create an NSButton that looks and acts -// like a hyperlink. The default styling is to look like blue, underlined text -// and to have the pointingHand cursor on mouse over. +// like a hyperlink. The default styling is to look like blue (#3367D6) text +// with no underline and to have the pointingHand cursor on mouse over. // // To use in Interface Builder: // 1. Drag out an NSButton. @@ -23,16 +23,26 @@ // // Use this if all of your text is a link. If you need text that contains // embedded links but also regular text, use HyperlinkTextView. + +namespace hyperlink_button_cell { + +enum class UI_BASE_EXPORT UnderlineBehavior { + ALWAYS, + NEVER, + ON_HOVER, +}; + +} // namespace hyperlink_button_cell + UI_BASE_EXPORT @interface HyperlinkButtonCell : NSButtonCell { base::scoped_nsobject<NSColor> textColor_; - BOOL shouldUnderline_; - BOOL underlineOnHover_; + hyperlink_button_cell::UnderlineBehavior underlineBehavior_; BOOL mouseIsInside_; } @property(nonatomic, retain) NSColor* textColor; -@property(nonatomic, assign) BOOL underlineOnHover; -@property(nonatomic, assign) BOOL shouldUnderline; +@property(nonatomic, assign) hyperlink_button_cell::UnderlineBehavior + underlineBehavior; + (NSColor*)defaultTextColor; diff --git a/chromium/ui/base/cocoa/controls/hyperlink_button_cell.mm b/chromium/ui/base/cocoa/controls/hyperlink_button_cell.mm index 57b70779cf3..e67e60db12e 100644 --- a/chromium/ui/base/cocoa/controls/hyperlink_button_cell.mm +++ b/chromium/ui/base/cocoa/controls/hyperlink_button_cell.mm @@ -4,6 +4,8 @@ #import "ui/base/cocoa/controls/hyperlink_button_cell.h" +using hyperlink_button_cell::UnderlineBehavior; + @interface HyperlinkButtonCell () - (void)customizeButtonCell; @end @@ -11,11 +13,14 @@ @implementation HyperlinkButtonCell @dynamic textColor; -@synthesize underlineOnHover = underlineOnHover_; -@synthesize shouldUnderline = shouldUnderline_; +@synthesize underlineBehavior = underlineBehavior_; + (NSColor*)defaultTextColor { - return [NSColor blueColor]; + // Equates to rgb(51, 103, 214) or #3367D6. + return [NSColor colorWithCalibratedRed:51.0/255.0 + green:103.0/255.0 + blue:214.0/255.0 + alpha:1.0]; } + (NSButton*)buttonWithString:(NSString*)string { @@ -65,7 +70,7 @@ - (void)customizeButtonCell { [self setBordered:NO]; [self setTextColor:[HyperlinkButtonCell defaultTextColor]]; - [self setShouldUnderline:YES]; + [self setUnderlineBehavior:UnderlineBehavior::NEVER]; CGFloat fontSize = [NSFont systemFontSizeForControlSize:[self controlSize]]; NSFont* font = [NSFont controlContentFontOfSize:fontSize]; @@ -87,9 +92,11 @@ // Creates the NSDictionary of attributes for the attributed string. - (NSDictionary*)linkAttributes { NSUInteger underlineMask = NSNoUnderlineStyle; - if (shouldUnderline_ && - (!underlineOnHover_ || (mouseIsInside_ && [self isEnabled]))) + if (underlineBehavior_ == UnderlineBehavior::ALWAYS || + (mouseIsInside_ && [self isEnabled] && + underlineBehavior_ == UnderlineBehavior::ON_HOVER)) { underlineMask = NSUnderlinePatternSolid | NSUnderlineStyleSingle; + } base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( [[NSParagraphStyle defaultParagraphStyle] mutableCopy]); @@ -127,14 +134,14 @@ [[NSCursor pointingHandCursor] push]; else [[NSCursor currentCursor] push]; - if (underlineOnHover_) + if (underlineBehavior_ == UnderlineBehavior::ON_HOVER) [[self controlView] setNeedsDisplay:YES]; } - (void)mouseExited:(NSEvent*)event { mouseIsInside_ = NO; [NSCursor pop]; - if (underlineOnHover_) + if (underlineBehavior_ == UnderlineBehavior::ON_HOVER) [[self controlView] setNeedsDisplay:YES]; } diff --git a/chromium/ui/base/cocoa/controls/hyperlink_button_cell_unittest.mm b/chromium/ui/base/cocoa/controls/hyperlink_button_cell_unittest.mm index 3e7c6110110..b45f7b714fe 100644 --- a/chromium/ui/base/cocoa/controls/hyperlink_button_cell_unittest.mm +++ b/chromium/ui/base/cocoa/controls/hyperlink_button_cell_unittest.mm @@ -11,6 +11,7 @@ #include "testing/gtest/include/gtest/gtest.h" #import "testing/gtest_mac.h" #include "testing/platform_test.h" +#include "ui/events/test/cocoa_test_event_utils.h" #import "ui/gfx/test/ui_cocoa_test_helper.h" namespace ui { @@ -75,13 +76,11 @@ TEST_F(HyperlinkButtonCellTest, SetTextColor) { } // Test mouse events. -// TODO(rsesek): See if we can synthesize mouse events to more accurately -// test this. TEST_F(HyperlinkButtonCellTest, MouseHover) { [[NSCursor disappearingItemCursor] push]; // Set a known state. - [cell_ mouseEntered:nil]; + [cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; EXPECT_EQ([NSCursor pointingHandCursor], [NSCursor currentCursor]); - [cell_ mouseExited:nil]; + [cell_ mouseExited:cocoa_test_event_utils::ExitEvent()]; EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]); [NSCursor pop]; } @@ -91,10 +90,10 @@ TEST_F(HyperlinkButtonCellTest, MouseHoverWhenDisabled) { [cell_ setEnabled:NO]; [[NSCursor disappearingItemCursor] push]; // Set a known state. - [cell_ mouseEntered:nil]; + [cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]); - [cell_ mouseExited:nil]; + [cell_ mouseExited:cocoa_test_event_utils::ExitEvent()]; EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]); [NSCursor pop]; [NSCursor pop]; @@ -102,17 +101,29 @@ TEST_F(HyperlinkButtonCellTest, MouseHoverWhenDisabled) { // Test underline on hover. TEST_F(HyperlinkButtonCellTest, UnderlineOnHover) { + // Default is for no underline. + EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); + [cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; + EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); + [cell_ mouseExited:cocoa_test_event_utils::ExitEvent()]; + EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); + + // Setting behavior to ALWAYS will result in always having an underline. + [cell_ setUnderlineBehavior:hyperlink_button_cell::UnderlineBehavior::ALWAYS]; EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); - [cell_ mouseEntered:nil]; + [cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); - [cell_ mouseExited:nil]; + [cell_ mouseExited:cocoa_test_event_utils::ExitEvent()]; EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); - [cell_ setUnderlineOnHover:YES]; + // Setting behavior to ON_HOVER will result in only underlining when the + // mouse is hovering over the link. + [cell_ setUnderlineBehavior: + hyperlink_button_cell::UnderlineBehavior::ON_HOVER]; EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); - [cell_ mouseEntered:nil]; + [cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes])); - [cell_ mouseExited:nil]; + [cell_ mouseExited:cocoa_test_event_utils::ExitEvent()]; EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes])); } diff --git a/chromium/ui/base/cocoa/controls/hyperlink_text_view.h b/chromium/ui/base/cocoa/controls/hyperlink_text_view.h index affe648d206..0a0cb4406bd 100644 --- a/chromium/ui/base/cocoa/controls/hyperlink_text_view.h +++ b/chromium/ui/base/cocoa/controls/hyperlink_text_view.h @@ -16,6 +16,7 @@ UI_BASE_EXPORT @private BOOL refusesFirstResponder_; BOOL drawsBackgroundUsingSuperview_; + BOOL isValidLink_; } @property(nonatomic, assign) BOOL drawsBackgroundUsingSuperview; @@ -26,7 +27,8 @@ UI_BASE_EXPORT withFont:(NSFont*)font messageColor:(NSColor*)messageColor; -// Marks a |range| within the given message as link. +// Marks a |range| within the given message as a link. Pass nil as the url to +// create a link that can neither be copied nor dragged. - (void)addLinkRange:(NSRange)range withURL:(NSString*)url linkColor:(NSColor*)linkColor; diff --git a/chromium/ui/base/cocoa/controls/hyperlink_text_view.mm b/chromium/ui/base/cocoa/controls/hyperlink_text_view.mm index c4936e28f2a..2a50e0f4a94 100644 --- a/chromium/ui/base/cocoa/controls/hyperlink_text_view.mm +++ b/chromium/ui/base/cocoa/controls/hyperlink_text_view.mm @@ -95,6 +95,7 @@ const float kTextBaselineShift = -1.0; refusesFirstResponder_ = NO; drawsBackgroundUsingSuperview_ = NO; + isValidLink_ = NO; } - (void)fixupCursor { @@ -102,6 +103,28 @@ const float kTextBaselineShift = -1.0; [[NSCursor arrowCursor] set]; } +// Only allow contextual menus (which allow copying of the link URL) if the link +// is a valid one. +- (NSMenu*)menuForEvent:(NSEvent*)e { + if (isValidLink_) + return [super menuForEvent:e]; + + return nil; +} + +// Only allow dragging of valid links. +- (BOOL)dragSelectionWithEvent:(NSEvent*)event + offset:(NSSize)mouseOffset + slideBack:(BOOL)slideBack { + if (isValidLink_) { + return [super dragSelectionWithEvent:event + offset:mouseOffset + slideBack:slideBack]; + } + + return NO; +} + - (void)setMessage:(NSString*)message withFont:(NSFont*)font messageColor:(NSColor*)messageColor { @@ -125,12 +148,15 @@ const float kTextBaselineShift = -1.0; - (void)addLinkRange:(NSRange)range withURL:(NSString*)url linkColor:(NSColor*)linkColor { - // When the NSLinkAttributeName attribute is used, AppKit makes the link - // draggable. If no URL is provided, dropping it on the tab strip will crash - // <http://crbug.com/528228>. Require that a URL is used, and that only a URL - // is used. - DCHECK_GT([url length], 0u); - DCHECK([NSURL URLWithString:url]); + // If a URL is provided, make sure it is a valid one. + if (url) { + DCHECK_GT([url length], 0u); + DCHECK([NSURL URLWithString:url]); + isValidLink_ = YES; + } else { + url = @""; + isValidLink_ = NO; + } NSDictionary* attributes = @{ NSForegroundColorAttributeName : linkColor, NSUnderlineStyleAttributeName : @(YES), diff --git a/chromium/ui/base/cocoa/focus_tracker.mm b/chromium/ui/base/cocoa/focus_tracker.mm index ef247cc8e9a..bf74b1a985c 100644 --- a/chromium/ui/base/cocoa/focus_tracker.mm +++ b/chromium/ui/base/cocoa/focus_tracker.mm @@ -4,7 +4,6 @@ #import "ui/base/cocoa/focus_tracker.h" -#include "base/basictypes.h" @implementation FocusTracker diff --git a/chromium/ui/base/cocoa/hover_image_button.h b/chromium/ui/base/cocoa/hover_image_button.h index a00163fb53b..e1a9773cb0a 100644 --- a/chromium/ui/base/cocoa/hover_image_button.h +++ b/chromium/ui/base/cocoa/hover_image_button.h @@ -20,6 +20,9 @@ UI_BASE_EXPORT base::scoped_nsobject<NSImage> pressedImage_; } +// Disables a click within the button from activating the application. +@property(nonatomic) BOOL disableActivationOnClick; + // Sets the default image. - (void)setDefaultImage:(NSImage*)image; diff --git a/chromium/ui/base/cocoa/hover_image_button.mm b/chromium/ui/base/cocoa/hover_image_button.mm index 3cdf509122e..75eea36a158 100644 --- a/chromium/ui/base/cocoa/hover_image_button.mm +++ b/chromium/ui/base/cocoa/hover_image_button.mm @@ -6,6 +6,8 @@ @implementation HoverImageButton +@synthesize disableActivationOnClick = disableActivationOnClick_; + - (void)drawRect:(NSRect)rect { if (hoverState_ == kHoverStateMouseDown && pressedImage_) { [super setImage:pressedImage_.get()]; @@ -30,4 +32,21 @@ pressedImage_.reset([image retain]); } +- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)theEvent { + // To avoid activating the app on a click inside the button, first tell + // the Appkit not to immediately order the HoverImageButton's window front in + // response to theEvent. + return disableActivationOnClick_; +} + +- (void)mouseDown:(NSEvent*)mouseDownEvent { + // If disabling activation on click, tell the Appkit to cancel window ordering + // for this mouse down. + if (disableActivationOnClick_) { + [[NSApplication sharedApplication] preventWindowOrdering]; + } + + [super mouseDown:mouseDownEvent]; +} + @end diff --git a/chromium/ui/base/cocoa/hover_image_button_unittest.mm b/chromium/ui/base/cocoa/hover_image_button_unittest.mm index 0dff3fc823c..c061d8f2d08 100644 --- a/chromium/ui/base/cocoa/hover_image_button_unittest.mm +++ b/chromium/ui/base/cocoa/hover_image_button_unittest.mm @@ -5,6 +5,7 @@ #import "ui/base/cocoa/hover_image_button.h" #import "base/mac/scoped_nsobject.h" +#include "ui/events/test/cocoa_test_event_utils.h" #import "ui/gfx/test/ui_cocoa_test_helper.h" namespace { @@ -35,10 +36,10 @@ TEST_F(HoverImageButtonTest, ImageSwap) { [button_ setDefaultImage:image]; [button_ setHoverImage:hover]; - [button_ mouseEntered:nil]; + [button_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; DrawRect(); EXPECT_EQ([button_ image], hover); - [button_ mouseExited:nil]; + [button_ mouseExited:cocoa_test_event_utils::ExitEvent()]; DrawRect(); EXPECT_NE([button_ image], hover); EXPECT_EQ([button_ image], image); diff --git a/chromium/ui/base/cocoa/menu_controller.h b/chromium/ui/base/cocoa/menu_controller.h index 1da667491a6..7e8e4acfcd8 100644 --- a/chromium/ui/base/cocoa/menu_controller.h +++ b/chromium/ui/base/cocoa/menu_controller.h @@ -15,6 +15,9 @@ namespace ui { class MenuModel; } +UI_BASE_EXPORT extern NSString* const kMenuControllerMenuWillOpenNotification; +UI_BASE_EXPORT extern NSString* const kMenuControllerMenuDidCloseNotification; + // A controller for the cross-platform menu model. The menu that's created // has the tag and represented object set for each menu item. The object is a // NSValue holding a pointer to the model for that level of the menu (to diff --git a/chromium/ui/base/cocoa/menu_controller.mm b/chromium/ui/base/cocoa/menu_controller.mm index 9faa6071e44..8c92b28b327 100644 --- a/chromium/ui/base/cocoa/menu_controller.mm +++ b/chromium/ui/base/cocoa/menu_controller.mm @@ -15,6 +15,11 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/text_elider.h" +NSString* const kMenuControllerMenuWillOpenNotification = + @"MenuControllerMenuWillOpen"; +NSString* const kMenuControllerMenuDidCloseNotification = + @"MenuControllerMenuDidClose"; + @interface MenuController (Private) - (void)addSeparatorToMenu:(NSMenu*)menu atIndex:(int)index; @@ -233,6 +238,9 @@ - (void)menuWillOpen:(NSMenu*)menu { isMenuOpen_ = YES; model_->MenuWillShow(); + [[NSNotificationCenter defaultCenter] + postNotificationName:kMenuControllerMenuWillOpenNotification + object:self]; } - (void)menuDidClose:(NSMenu*)menu { @@ -240,6 +248,9 @@ model_->MenuClosed(); isMenuOpen_ = NO; } + [[NSNotificationCenter defaultCenter] + postNotificationName:kMenuControllerMenuDidCloseNotification + object:self]; } @end diff --git a/chromium/ui/base/cocoa/menu_controller_unittest.mm b/chromium/ui/base/cocoa/menu_controller_unittest.mm index 36b0e1308d7..5bda6b6c096 100644 --- a/chromium/ui/base/cocoa/menu_controller_unittest.mm +++ b/chromium/ui/base/cocoa/menu_controller_unittest.mm @@ -11,6 +11,7 @@ #import "ui/base/cocoa/menu_controller.h" #include "ui/base/models/simple_menu_model.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/events/test/cocoa_test_event_utils.h" #include "ui/gfx/image/image.h" #import "ui/gfx/test/ui_cocoa_test_helper.h" #include "ui/resources/grit/ui_resources.h" @@ -372,7 +373,8 @@ TEST_F(MenuControllerTest, OpenClose) { // Pop open the menu, which will spin an event-tracking run loop. [NSMenu popUpContextMenu:[menu menu] - withEvent:nil + withEvent:cocoa_test_event_utils::RightMouseDownAtPoint( + NSZeroPoint) forView:[test_window() contentView]]; EXPECT_FALSE([menu isMenuOpen]); diff --git a/chromium/ui/base/cocoa/remote_layer_api.h b/chromium/ui/base/cocoa/remote_layer_api.h index 8d704af3d2f..7b97c7e5eb1 100644 --- a/chromium/ui/base/cocoa/remote_layer_api.h +++ b/chromium/ui/base/cocoa/remote_layer_api.h @@ -9,6 +9,8 @@ #import <Cocoa/Cocoa.h> #endif // __OBJC__ +#include <stdint.h> + #include "ui/base/ui_base_export.h" // The CGSConnectionID is used to create the CAContext in the process that is diff --git a/chromium/ui/base/cocoa/scoped_cg_context_smooth_fonts.h b/chromium/ui/base/cocoa/scoped_cg_context_smooth_fonts.h index 1624d463970..f080d78e199 100644 --- a/chromium/ui/base/cocoa/scoped_cg_context_smooth_fonts.h +++ b/chromium/ui/base/cocoa/scoped_cg_context_smooth_fonts.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_COCOA_SCOPED_CG_CONTEXT_SMOOTH_FONTS_H_ #define UI_BASE_COCOA_SCOPED_CG_CONTEXT_SMOOTH_FONTS_H_ +#include "base/macros.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" diff --git a/chromium/ui/base/cocoa/three_part_image.h b/chromium/ui/base/cocoa/three_part_image.h index 01a66911bcb..ebeef5fdc4d 100644 --- a/chromium/ui/base/cocoa/three_part_image.h +++ b/chromium/ui/base/cocoa/three_part_image.h @@ -8,6 +8,7 @@ #import <Cocoa/Cocoa.h> #include "base/mac/scoped_nsobject.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/cocoa/tracking_area.h b/chromium/ui/base/cocoa/tracking_area.h index 361fd6df4bc..07eb70b5f3d 100644 --- a/chromium/ui/base/cocoa/tracking_area.h +++ b/chromium/ui/base/cocoa/tracking_area.h @@ -8,6 +8,7 @@ #import <AppKit/AppKit.h> #include "base/mac/scoped_nsobject.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" @class CrTrackingAreaOwnerProxy; diff --git a/chromium/ui/base/cursor/cursor_loader.h b/chromium/ui/base/cursor/cursor_loader.h index f69d23c592b..cf90846b648 100644 --- a/chromium/ui/base/cursor/cursor_loader.h +++ b/chromium/ui/base/cursor/cursor_loader.h @@ -6,6 +6,7 @@ #define UI_BASE_CURSOR_CURSOR_LOADER_H_ #include "base/logging.h" +#include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/display.h" diff --git a/chromium/ui/base/cursor/cursor_loader_ozone.h b/chromium/ui/base/cursor/cursor_loader_ozone.h index 26f8bac7c2c..6cd67dc6f0b 100644 --- a/chromium/ui/base/cursor/cursor_loader_ozone.h +++ b/chromium/ui/base/cursor/cursor_loader_ozone.h @@ -7,6 +7,7 @@ #include <map> +#include "base/macros.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_loader.h" diff --git a/chromium/ui/base/cursor/cursor_loader_win.h b/chromium/ui/base/cursor/cursor_loader_win.h index fe36da32b78..270198b283a 100644 --- a/chromium/ui/base/cursor/cursor_loader_win.h +++ b/chromium/ui/base/cursor/cursor_loader_win.h @@ -6,6 +6,7 @@ #define UI_BASE_CURSOR_CURSOR_LOADER_WIN_H_ #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/cursor/cursor_loader.h" namespace ui { diff --git a/chromium/ui/base/cursor/cursor_loader_x11.cc b/chromium/ui/base/cursor/cursor_loader_x11.cc index 8ad1f0e3e1d..aff40d2f0ae 100644 --- a/chromium/ui/base/cursor/cursor_loader_x11.cc +++ b/chromium/ui/base/cursor/cursor_loader_x11.cc @@ -9,6 +9,7 @@ #include <X11/Xlib.h> #include "base/logging.h" +#include "build/build_config.h" #include "skia/ext/image_operations.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_util.h" diff --git a/chromium/ui/base/cursor/cursor_loader_x11.h b/chromium/ui/base/cursor/cursor_loader_x11.h index 8c947d175f7..7523db330c0 100644 --- a/chromium/ui/base/cursor/cursor_loader_x11.h +++ b/chromium/ui/base/cursor/cursor_loader_x11.h @@ -9,6 +9,7 @@ #include <map> #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_loader.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/cursor/cursor_util.cc b/chromium/ui/base/cursor/cursor_util.cc index 6eb893e3732..0e1d36e5838 100644 --- a/chromium/ui/base/cursor/cursor_util.cc +++ b/chromium/ui/base/cursor/cursor_util.cc @@ -15,10 +15,43 @@ namespace ui { +namespace { + +// Converts the SkBitmap to use a different alpha type. Returns true if bitmap +// was modified, otherwise returns false. +bool ConvertSkBitmapAlphaType(SkBitmap* bitmap, SkAlphaType alpha_type) { + if (bitmap->info().alphaType() == alpha_type) { + return false; + } + + // Copy the bitmap into a temporary buffer. This will convert alpha type. + SkImageInfo image_info = + SkImageInfo::MakeN32(bitmap->width(), bitmap->height(), alpha_type); + std::vector<char> buffer(bitmap->getSize()); + bitmap->readPixels(image_info, &buffer[0], image_info.minRowBytes(), 0, 0); + // Read the temporary buffer back into the original bitmap. + bitmap->reset(); + bitmap->allocPixels(image_info); + memcpy(bitmap->getPixels(), &buffer[0], buffer.size()); + + return true; +} + +} // namespace + void ScaleAndRotateCursorBitmapAndHotpoint(float scale, gfx::Display::Rotation rotation, SkBitmap* bitmap, gfx::Point* hotpoint) { + // SkBitmapOperations::Rotate() needs the bitmap to have premultiplied alpha, + // so convert bitmap alpha type if we are going to rotate. + bool was_converted = false; + if (rotation != gfx::Display::ROTATE_0 && + bitmap->info().alphaType() == kUnpremul_SkAlphaType) { + ConvertSkBitmapAlphaType(bitmap, kPremul_SkAlphaType); + was_converted = true; + } + switch (rotation) { case gfx::Display::ROTATE_0: break; @@ -40,6 +73,10 @@ void ScaleAndRotateCursorBitmapAndHotpoint(float scale, break; } + if (was_converted) { + ConvertSkBitmapAlphaType(bitmap, kUnpremul_SkAlphaType); + } + if (scale < FLT_EPSILON) { NOTREACHED() << "Scale must be larger than 0."; scale = 1.0f; @@ -56,7 +93,7 @@ void ScaleAndRotateCursorBitmapAndHotpoint(float scale, skia::ImageOperations::RESIZE_BETTER, scaled_size.width(), scaled_size.height()); - *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); + *hotpoint = gfx::ScaleToFlooredPoint(*hotpoint, scale); } void GetImageCursorBitmap(int resource_id, diff --git a/chromium/ui/base/cursor/cursors_aura.cc b/chromium/ui/base/cursor/cursors_aura.cc index d36282bda3e..8dca8ff1500 100644 --- a/chromium/ui/base/cursor/cursors_aura.cc +++ b/chromium/ui/base/cursor/cursors_aura.cc @@ -4,6 +4,9 @@ #include "ui/base/cursor/cursors_aura.h" +#include <stddef.h> + +#include "base/macros.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/geometry/point.h" @@ -128,8 +131,8 @@ const CursorData kLargeCursors[] = { }; const CursorData kAnimatedCursors[] = { - {ui::kCursorWait, IDR_THROBBER, {7, 7}, {14, 14}}, - {ui::kCursorProgress, IDR_THROBBER, {7, 7}, {14, 14}}, + {ui::kCursorWait, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, + {ui::kCursorProgress, IDR_AURA_CURSOR_THROBBER, {7, 7}, {14, 14}}, }; const CursorSet kCursorSets[] = { diff --git a/chromium/ui/base/cursor/image_cursors.cc b/chromium/ui/base/cursor/image_cursors.cc index e69a794588d..54b851e2479 100644 --- a/chromium/ui/base/cursor/image_cursors.cc +++ b/chromium/ui/base/cursor/image_cursors.cc @@ -5,8 +5,10 @@ #include "ui/base/cursor/image_cursors.h" #include <float.h> +#include <stddef.h> #include "base/logging.h" +#include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_loader.h" diff --git a/chromium/ui/base/cursor/image_cursors.h b/chromium/ui/base/cursor/image_cursors.h index 25676ca462f..be3c7fbf2fa 100644 --- a/chromium/ui/base/cursor/image_cursors.h +++ b/chromium/ui/base/cursor/image_cursors.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_CURSOR_IMAGE_CURSORS_H_ #define UI_BASE_CURSOR_IMAGE_CURSORS_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "ui/base/cursor/cursor.h" diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h index 53c599903b6..e621c5e370e 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h @@ -7,6 +7,7 @@ #include <map> +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/cursor/cursor.h" diff --git a/chromium/ui/base/default_theme_provider.cc b/chromium/ui/base/default_theme_provider.cc index 210ff1899b9..8f1f52bd4df 100644 --- a/chromium/ui/base/default_theme_provider.cc +++ b/chromium/ui/base/default_theme_provider.cc @@ -5,6 +5,7 @@ #include "ui/base/default_theme_provider.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/color_palette.h" #include "ui/gfx/image/image_skia.h" namespace ui { @@ -13,17 +14,12 @@ DefaultThemeProvider::DefaultThemeProvider() {} DefaultThemeProvider::~DefaultThemeProvider() {} -bool DefaultThemeProvider::UsingSystemTheme() const { - return true; -} - gfx::ImageSkia* DefaultThemeProvider::GetImageSkiaNamed(int id) const { return ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); } SkColor DefaultThemeProvider::GetColor(int id) const { - // Return debugging-blue. - return 0xff0000ff; + return gfx::kPlaceholderColor; } int DefaultThemeProvider::GetDisplayProperty(int id) const { diff --git a/chromium/ui/base/default_theme_provider.h b/chromium/ui/base/default_theme_provider.h index 173442deaa2..35d47b2fedb 100644 --- a/chromium/ui/base/default_theme_provider.h +++ b/chromium/ui/base/default_theme_provider.h @@ -7,8 +7,9 @@ #include <vector> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" +#include "build/build_config.h" #include "ui/base/theme_provider.h" #include "ui/base/ui_base_export.h" @@ -24,7 +25,6 @@ class UI_BASE_EXPORT DefaultThemeProvider : public ThemeProvider { ~DefaultThemeProvider() override; // Overridden from ui::ThemeProvider: - bool UsingSystemTheme() const override; gfx::ImageSkia* GetImageSkiaNamed(int id) const override; SkColor GetColor(int id) const override; int GetDisplayProperty(int id) const override; @@ -34,6 +34,7 @@ class UI_BASE_EXPORT DefaultThemeProvider : public ThemeProvider { const override; #if defined(OS_MACOSX) + bool UsingSystemTheme() const override; NSImage* GetNSImageNamed(int id) const override; NSColor* GetNSImageColorNamed(int id) const override; NSColor* GetNSColor(int id) const override; diff --git a/chromium/ui/base/default_theme_provider_mac.mm b/chromium/ui/base/default_theme_provider_mac.mm index 6d5e684dabf..71b0f8eb86b 100644 --- a/chromium/ui/base/default_theme_provider_mac.mm +++ b/chromium/ui/base/default_theme_provider_mac.mm @@ -10,6 +10,10 @@ namespace ui { +bool DefaultThemeProvider::UsingSystemTheme() const { + return true; +} + NSImage* DefaultThemeProvider::GetNSImageNamed(int id) const { return ResourceBundle::GetSharedInstance(). GetNativeImageNamed(id).ToNSImage(); diff --git a/chromium/ui/base/device_form_factor_android.cc b/chromium/ui/base/device_form_factor_android.cc index e7ed06b82f0..9cc21ba6047 100644 --- a/chromium/ui/base/device_form_factor_android.cc +++ b/chromium/ui/base/device_form_factor_android.cc @@ -4,6 +4,7 @@ #include "ui/base/device_form_factor_android.h" +#include "base/android/context_utils.h" #include "base/android/jni_android.h" #include "jni/DeviceFormFactor_jni.h" diff --git a/chromium/ui/base/dragdrop/download_file_interface.h b/chromium/ui/base/dragdrop/download_file_interface.h index 327fe79ebe1..db82ff2d2c6 100644 --- a/chromium/ui/base/dragdrop/download_file_interface.h +++ b/chromium/ui/base/dragdrop/download_file_interface.h @@ -7,7 +7,6 @@ #include "build/build_config.h" -#include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/dragdrop/drag_drop_types.h b/chromium/ui/base/dragdrop/drag_drop_types.h index 6b25f1323ca..cc54560d860 100644 --- a/chromium/ui/base/dragdrop/drag_drop_types.h +++ b/chromium/ui/base/dragdrop/drag_drop_types.h @@ -5,7 +5,9 @@ #ifndef UI_BASE_DRAGDROP_DRAG_DROP_TYPES_H_ #define UI_BASE_DRAGDROP_DRAG_DROP_TYPES_H_ -#include "base/basictypes.h" +#include <stdint.h> + +#include "build/build_config.h" #include "ui/base/ui_base_export.h" namespace ui { @@ -27,8 +29,8 @@ class UI_BASE_EXPORT DragDropTypes { }; #if defined(OS_WIN) - static uint32 DragOperationToDropEffect(int drag_operation); - static int DropEffectToDragOperation(uint32 effect); + static uint32_t DragOperationToDropEffect(int drag_operation); + static int DropEffectToDragOperation(uint32_t effect); #endif }; diff --git a/chromium/ui/base/dragdrop/drag_drop_types_win.cc b/chromium/ui/base/dragdrop/drag_drop_types_win.cc index d6beff56a82..d189b82f5c3 100644 --- a/chromium/ui/base/dragdrop/drag_drop_types_win.cc +++ b/chromium/ui/base/dragdrop/drag_drop_types_win.cc @@ -5,11 +5,11 @@ #include "ui/base/dragdrop/drag_drop_types.h" #include <oleidl.h> +#include <stdint.h> namespace ui { -int ui::DragDropTypes::DropEffectToDragOperation( - uint32 effect) { +int ui::DragDropTypes::DropEffectToDragOperation(uint32_t effect) { int drag_operation = DRAG_NONE; if (effect & DROPEFFECT_LINK) drag_operation |= DRAG_LINK; @@ -20,8 +20,8 @@ int ui::DragDropTypes::DropEffectToDragOperation( return drag_operation; } -uint32 ui::DragDropTypes::DragOperationToDropEffect(int drag_operation) { - uint32 drop_effect = DROPEFFECT_NONE; +uint32_t ui::DragDropTypes::DragOperationToDropEffect(int drag_operation) { + uint32_t drop_effect = DROPEFFECT_NONE; if (drag_operation & DRAG_LINK) drop_effect |= DROPEFFECT_LINK; if (drag_operation & DRAG_COPY) diff --git a/chromium/ui/base/dragdrop/drag_source_win.h b/chromium/ui/base/dragdrop/drag_source_win.h index 9d442a89463..6051de2c7a7 100644 --- a/chromium/ui/base/dragdrop/drag_source_win.h +++ b/chromium/ui/base/dragdrop/drag_source_win.h @@ -8,7 +8,7 @@ #include <objidl.h> #include <wrl/implements.h> -#include "base/basictypes.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/dragdrop/drag_utils.cc b/chromium/ui/base/dragdrop/drag_utils.cc index e8723c8776d..3e69b15c8c4 100644 --- a/chromium/ui/base/dragdrop/drag_utils.cc +++ b/chromium/ui/base/dragdrop/drag_utils.cc @@ -6,7 +6,9 @@ #include "base/files/file_util.h" #include "base/logging.h" +#include "base/macros.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font_list.h" diff --git a/chromium/ui/base/dragdrop/drag_utils_win.cc b/chromium/ui/base/dragdrop/drag_utils_win.cc index 9fedd4202a3..1921338f5a2 100644 --- a/chromium/ui/base/dragdrop/drag_utils_win.cc +++ b/chromium/ui/base/dragdrop/drag_utils_win.cc @@ -7,6 +7,7 @@ #include <objidl.h> #include <shlobj.h> #include <shobjidl.h> +#include <stddef.h> #include "base/win/scoped_comptr.h" #include "base/win/scoped_hdc.h" diff --git a/chromium/ui/base/dragdrop/drop_target_event.cc b/chromium/ui/base/dragdrop/drop_target_event.cc index bbbf84a87cf..213fbeeddf0 100644 --- a/chromium/ui/base/dragdrop/drop_target_event.cc +++ b/chromium/ui/base/dragdrop/drop_target_event.cc @@ -16,13 +16,12 @@ DropTargetEvent::DropTargetEvent(const OSExchangeData& data, const gfx::Point& root_location, int source_operations) : LocatedEvent(ET_DROP_TARGET_EVENT, - location, - root_location, + gfx::PointF(location), + gfx::PointF(root_location), EventTimeForNow(), 0), data_(data), - source_operations_(source_operations) { -} + source_operations_(source_operations) {} } // namespace ui diff --git a/chromium/ui/base/dragdrop/drop_target_event.h b/chromium/ui/base/dragdrop/drop_target_event.h index 18c0630f52f..adef99f5d7a 100644 --- a/chromium/ui/base/dragdrop/drop_target_event.h +++ b/chromium/ui/base/dragdrop/drop_target_event.h @@ -5,8 +5,9 @@ #ifndef UI_BASE_DRAGDROP_DROP_TARGET_EVENT_H_ #define UI_BASE_DRAGDROP_DROP_TARGET_EVENT_H_ -#include "ui/events/event.h" +#include "base/macros.h" #include "ui/base/dragdrop/os_exchange_data.h" +#include "ui/events/event.h" namespace ui { diff --git a/chromium/ui/base/dragdrop/drop_target_win.h b/chromium/ui/base/dragdrop/drop_target_win.h index 2cc5493cc78..4694d2e641f 100644 --- a/chromium/ui/base/dragdrop/drop_target_win.h +++ b/chromium/ui/base/dragdrop/drop_target_win.h @@ -7,6 +7,7 @@ #include <objidl.h> +#include "base/macros.h" #include "base/memory/ref_counted.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/dragdrop/os_exchange_data.cc b/chromium/ui/base/dragdrop/os_exchange_data.cc index 69d13edd4a2..00e58191f39 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data.cc @@ -5,6 +5,7 @@ #include "ui/base/dragdrop/os_exchange_data.h" #include "base/pickle.h" +#include "build/build_config.h" #include "url/gurl.h" namespace ui { @@ -52,7 +53,7 @@ void OSExchangeData::SetFilenames( provider_->SetFilenames(filenames); } -void OSExchangeData::SetPickledData(const CustomFormat& format, +void OSExchangeData::SetPickledData(const Clipboard::FormatType& format, const base::Pickle& data) { provider_->SetPickledData(format, data); } @@ -71,12 +72,11 @@ bool OSExchangeData::GetFilename(base::FilePath* path) const { return provider_->GetFilename(path); } -bool OSExchangeData::GetFilenames( - std::vector<FileInfo>* filenames) const { +bool OSExchangeData::GetFilenames(std::vector<FileInfo>* filenames) const { return provider_->GetFilenames(filenames); } -bool OSExchangeData::GetPickledData(const CustomFormat& format, +bool OSExchangeData::GetPickledData(const Clipboard::FormatType& format, base::Pickle* data) const { return provider_->GetPickledData(format, data); } @@ -93,13 +93,14 @@ bool OSExchangeData::HasFile() const { return provider_->HasFile(); } -bool OSExchangeData::HasCustomFormat(const CustomFormat& format) const { +bool OSExchangeData::HasCustomFormat( + const Clipboard::FormatType& format) const { return provider_->HasCustomFormat(format); } bool OSExchangeData::HasAnyFormat( int formats, - const std::set<CustomFormat>& custom_formats) const { + const std::set<Clipboard::FormatType>& format_types) const { if ((formats & STRING) != 0 && HasString()) return true; if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES)) @@ -114,9 +115,8 @@ bool OSExchangeData::HasAnyFormat( #endif if ((formats & FILE_NAME) != 0 && provider_->HasFile()) return true; - for (std::set<CustomFormat>::const_iterator i = custom_formats.begin(); - i != custom_formats.end(); ++i) { - if (HasCustomFormat(*i)) + for (const auto& format : format_types) { + if (HasCustomFormat(format)) return true; } return false; diff --git a/chromium/ui/base/dragdrop/os_exchange_data.h b/chromium/ui/base/dragdrop/os_exchange_data.h index 6bbf9186f6d..5917c8426f8 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.h +++ b/chromium/ui/base/dragdrop/os_exchange_data.h @@ -14,8 +14,8 @@ #include <objidl.h> #endif -#include "base/basictypes.h" #include "base/files/file_path.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "ui/base/clipboard/clipboard.h" #include "ui/base/dragdrop/download_file_interface.h" @@ -52,11 +52,6 @@ struct FileInfo; // compiled on windows. class UI_BASE_EXPORT OSExchangeData { public: - // CustomFormats are used for non-standard data types. For example, bookmark - // nodes are written using a CustomFormat. - // TODO(dcheng): Remove this completely and just use Clipboard::FormatType. - typedef Clipboard::FormatType CustomFormat; - // Enumeration of the known formats. enum Format { STRING = 1 << 0, @@ -100,9 +95,8 @@ class UI_BASE_EXPORT OSExchangeData { virtual void SetString(const base::string16& data) = 0; virtual void SetURL(const GURL& url, const base::string16& title) = 0; virtual void SetFilename(const base::FilePath& path) = 0; - virtual void SetFilenames( - const std::vector<FileInfo>& file_names) = 0; - virtual void SetPickledData(const CustomFormat& format, + virtual void SetFilenames(const std::vector<FileInfo>& file_names) = 0; + virtual void SetPickledData(const Clipboard::FormatType& format, const base::Pickle& data) = 0; virtual bool GetString(base::string16* data) const = 0; @@ -110,15 +104,14 @@ class UI_BASE_EXPORT OSExchangeData { GURL* url, base::string16* title) const = 0; virtual bool GetFilename(base::FilePath* path) const = 0; - virtual bool GetFilenames( - std::vector<FileInfo>* file_names) const = 0; - virtual bool GetPickledData(const CustomFormat& format, + virtual bool GetFilenames(std::vector<FileInfo>* file_names) const = 0; + virtual bool GetPickledData(const Clipboard::FormatType& format, base::Pickle* data) const = 0; virtual bool HasString() const = 0; virtual bool HasURL(FilenameToURLPolicy policy) const = 0; virtual bool HasFile() const = 0; - virtual bool HasCustomFormat(const CustomFormat& format) const = 0; + virtual bool HasCustomFormat(const Clipboard::FormatType& format) const = 0; #if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN) virtual void SetFileContents(const base::FilePath& filename, @@ -184,7 +177,8 @@ class UI_BASE_EXPORT OSExchangeData { void SetFilenames( const std::vector<FileInfo>& file_names); // Adds pickled data of the specified format. - void SetPickledData(const CustomFormat& format, const base::Pickle& data); + void SetPickledData(const Clipboard::FormatType& format, + const base::Pickle& data); // These functions retrieve data of the specified type. If data exists, the // functions return and the result is in the out parameter. If the data does @@ -198,21 +192,21 @@ class UI_BASE_EXPORT OSExchangeData { base::string16* title) const; // Return the path of a file, if available. bool GetFilename(base::FilePath* path) const; - bool GetFilenames( - std::vector<FileInfo>* file_names) const; - bool GetPickledData(const CustomFormat& format, base::Pickle* data) const; + bool GetFilenames(std::vector<FileInfo>* file_names) const; + bool GetPickledData(const Clipboard::FormatType& format, + base::Pickle* data) const; // Test whether or not data of certain types is present, without actually // returning anything. bool HasString() const; bool HasURL(FilenameToURLPolicy policy) const; bool HasFile() const; - bool HasCustomFormat(const CustomFormat& format) const; + bool HasCustomFormat(const Clipboard::FormatType& format) const; // Returns true if this OSExchangeData has data in any of the formats in // |formats| or any custom format in |custom_formats|. bool HasAnyFormat(int formats, - const std::set<CustomFormat>& custom_formats) const; + const std::set<Clipboard::FormatType>& types) const; #if defined(OS_WIN) // Adds the bytes of a file (CFSTR_FILECONTENTS and CFSTR_FILEDESCRIPTOR on diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc index d633ccc51a2..9cd070a29e6 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc @@ -73,7 +73,7 @@ void OSExchangeDataProviderAura::SetFilenames( } void OSExchangeDataProviderAura::SetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, const base::Pickle& data) { pickle_data_[format] = data; formats_ |= OSExchangeData::PICKLED_DATA; @@ -121,7 +121,7 @@ bool OSExchangeDataProviderAura::GetFilenames( } bool OSExchangeDataProviderAura::GetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, base::Pickle* data) const { PickleData::const_iterator i = pickle_data_.find(format); if (i == pickle_data_.end()) @@ -150,7 +150,7 @@ bool OSExchangeDataProviderAura::HasFile() const { } bool OSExchangeDataProviderAura::HasCustomFormat( - const OSExchangeData::CustomFormat& format) const { + const Clipboard::FormatType& format) const { return pickle_data_.find(format) != pickle_data_.end(); } diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h index 87f0b5a6b09..327106ffe19 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h @@ -8,6 +8,7 @@ #include <map> #include "base/files/file_path.h" +#include "base/macros.h" #include "base/pickle.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/geometry/vector2d.h" @@ -33,7 +34,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderAura void SetURL(const GURL& url, const base::string16& title) override; void SetFilename(const base::FilePath& path) override; void SetFilenames(const std::vector<FileInfo>& filenames) override; - void SetPickledData(const OSExchangeData::CustomFormat& format, + void SetPickledData(const Clipboard::FormatType& format, const base::Pickle& data) override; bool GetString(base::string16* data) const override; bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy, @@ -41,12 +42,12 @@ class UI_BASE_EXPORT OSExchangeDataProviderAura base::string16* title) const override; bool GetFilename(base::FilePath* path) const override; bool GetFilenames(std::vector<FileInfo>* filenames) const override; - bool GetPickledData(const OSExchangeData::CustomFormat& format, + bool GetPickledData(const Clipboard::FormatType& format, base::Pickle* data) const override; bool HasString() const override; bool HasURL(OSExchangeData::FilenameToURLPolicy policy) const override; bool HasFile() const override; - bool HasCustomFormat(const OSExchangeData::CustomFormat& format) const + bool HasCustomFormat(const Clipboard::FormatType& format) const override; void SetHtml(const base::string16& html, const GURL& base_url) override; @@ -58,7 +59,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderAura const gfx::Vector2d& GetDragImageOffset() const override; private: - typedef std::map<OSExchangeData::CustomFormat, base::Pickle> PickleData; + typedef std::map<Clipboard::FormatType, base::Pickle> PickleData; // Returns true if |formats_| contains a string format and the string can be // parsed as a URL. diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc index 73ec4bf847e..e2bba470108 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc @@ -206,7 +206,7 @@ void OSExchangeDataProviderAuraX11::SetFilenames( } void OSExchangeDataProviderAuraX11::SetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, const base::Pickle& pickle) { const unsigned char* data = reinterpret_cast<const unsigned char*>(pickle.data()); @@ -325,7 +325,7 @@ bool OSExchangeDataProviderAuraX11::GetFilenames( } bool OSExchangeDataProviderAuraX11::GetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, base::Pickle* pickle) const { std::vector< ::Atom> requested_types; requested_types.push_back(atom_cache_.GetAtom(format.ToString().c_str())); @@ -409,7 +409,7 @@ bool OSExchangeDataProviderAuraX11::HasFile() const { } bool OSExchangeDataProviderAuraX11::HasCustomFormat( - const OSExchangeData::CustomFormat& format) const { + const Clipboard::FormatType& format) const { std::vector< ::Atom> url_atoms; url_atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); std::vector< ::Atom> requested_types; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.h index 959b6a68aa1..2f590691be3 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_aurax11.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURAX11_H_ +#include <stdint.h> #include <X11/Xlib.h> // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. @@ -13,6 +14,7 @@ #include <map> #include "base/files/file_path.h" +#include "base/macros.h" #include "base/pickle.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/x/selection_owner.h" @@ -68,7 +70,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderAuraX11 void SetURL(const GURL& url, const base::string16& title) override; void SetFilename(const base::FilePath& path) override; void SetFilenames(const std::vector<FileInfo>& filenames) override; - void SetPickledData(const OSExchangeData::CustomFormat& format, + void SetPickledData(const Clipboard::FormatType& format, const base::Pickle& pickle) override; bool GetString(base::string16* data) const override; bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy, @@ -76,13 +78,12 @@ class UI_BASE_EXPORT OSExchangeDataProviderAuraX11 base::string16* title) const override; bool GetFilename(base::FilePath* path) const override; bool GetFilenames(std::vector<FileInfo>* filenames) const override; - bool GetPickledData(const OSExchangeData::CustomFormat& format, + bool GetPickledData(const Clipboard::FormatType& format, base::Pickle* pickle) const override; bool HasString() const override; bool HasURL(OSExchangeData::FilenameToURLPolicy policy) const override; bool HasFile() const override; - bool HasCustomFormat( - const OSExchangeData::CustomFormat& format) const override; + bool HasCustomFormat(const Clipboard::FormatType& format) const override; void SetFileContents(const base::FilePath& filename, const std::string& file_contents) override; @@ -101,7 +102,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderAuraX11 private: friend class OSExchangeDataProviderAuraX11Test; - typedef std::map<OSExchangeData::CustomFormat, base::Pickle> PickleData; + typedef std::map<Clipboard::FormatType, base::Pickle> PickleData; // Returns true if |formats_| contains a string format and the string can be // parsed as a URL. diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h index a22b3f2859f..c619ab9d806 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h @@ -6,6 +6,7 @@ #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_MAC_H_ #import "base/mac/scoped_nsobject.h" +#include "base/macros.h" #include "ui/base/dragdrop/os_exchange_data.h" @class NSPasteboard; @@ -28,7 +29,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderMac void SetURL(const GURL& url, const base::string16& title) override; void SetFilename(const base::FilePath& path) override; void SetFilenames(const std::vector<FileInfo>& filenames) override; - void SetPickledData(const OSExchangeData::CustomFormat& format, + void SetPickledData(const Clipboard::FormatType& format, const base::Pickle& data) override; bool GetString(base::string16* data) const override; bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy, @@ -36,13 +37,12 @@ class UI_BASE_EXPORT OSExchangeDataProviderMac base::string16* title) const override; bool GetFilename(base::FilePath* path) const override; bool GetFilenames(std::vector<FileInfo>* filenames) const override; - bool GetPickledData(const OSExchangeData::CustomFormat& format, + bool GetPickledData(const Clipboard::FormatType& format, base::Pickle* data) const override; bool HasString() const override; bool HasURL(OSExchangeData::FilenameToURLPolicy policy) const override; bool HasFile() const override; - bool HasCustomFormat( - const OSExchangeData::CustomFormat& format) const override; + bool HasCustomFormat(const Clipboard::FormatType& format) const override; private: base::scoped_nsobject<NSPasteboard> pasteboard_; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm index 1178f1d3f63..72d647f1406 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm @@ -63,7 +63,7 @@ void OSExchangeDataProviderMac::SetFilenames( } void OSExchangeDataProviderMac::SetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, const base::Pickle& data) { NSData* ns_data = [NSData dataWithBytes:data.data() length:data.size()]; [pasteboard_ setData:ns_data forType:format.ToNSString()]; @@ -135,7 +135,7 @@ bool OSExchangeDataProviderMac::GetFilenames( } bool OSExchangeDataProviderMac::GetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, base::Pickle* data) const { DCHECK(data); NSData* ns_data = [pasteboard_ dataForType:format.ToNSString()]; @@ -164,7 +164,7 @@ bool OSExchangeDataProviderMac::HasFile() const { } bool OSExchangeDataProviderMac::HasCustomFormat( - const OSExchangeData::CustomFormat& format) const { + const Clipboard::FormatType& format) const { return [[pasteboard_ types] containsObject:format.ToNSString()]; } diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc index 0389429b0ae..47f1e0bb1d2 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -4,12 +4,14 @@ #include "ui/base/dragdrop/os_exchange_data_provider_win.h" +#include <stdint.h> + #include <algorithm> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/i18n/file_util_icu.h" #include "base/logging.h" +#include "base/macros.h" #include "base/pickle.h" #include "base/strings/utf_string_conversions.h" #include "base/win/scoped_hglobal.h" @@ -23,9 +25,9 @@ namespace ui { -static const OSExchangeData::CustomFormat& GetRendererTaintCustomType() { +static const Clipboard::FormatType& GetRendererTaintFormatType() { CR_DEFINE_STATIC_LOCAL( - ui::OSExchangeData::CustomFormat, + Clipboard::FormatType, format, (ui::Clipboard::GetFormatType("chromium/x-renderer-taint"))); return format; @@ -281,11 +283,11 @@ OSExchangeData::Provider* OSExchangeDataProviderWin::Clone() const { void OSExchangeDataProviderWin::MarkOriginatedFromRenderer() { STGMEDIUM* storage = GetStorageForString(std::string()); data_->contents_.push_back(new DataObjectImpl::StoredDataInfo( - GetRendererTaintCustomType().ToFormatEtc(), storage)); + GetRendererTaintFormatType().ToFormatEtc(), storage)); } bool OSExchangeDataProviderWin::DidOriginateFromRenderer() const { - return HasCustomFormat(GetRendererTaintCustomType()); + return HasCustomFormat(GetRendererTaintFormatType()); } void OSExchangeDataProviderWin::SetString(const base::string16& data) { @@ -363,7 +365,7 @@ void OSExchangeDataProviderWin::SetFilenames( } void OSExchangeDataProviderWin::SetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, const base::Pickle& data) { STGMEDIUM* storage = GetStorageForBytes(data.data(), data.size()); data_->contents_.push_back( @@ -448,7 +450,7 @@ bool OSExchangeDataProviderWin::GetFilenames( } bool OSExchangeDataProviderWin::GetPickledData( - const OSExchangeData::CustomFormat& format, + const Clipboard::FormatType& format, base::Pickle* data) const { DCHECK(data); bool success = false; @@ -512,7 +514,7 @@ bool OSExchangeDataProviderWin::HasHtml() const { } bool OSExchangeDataProviderWin::HasCustomFormat( - const OSExchangeData::CustomFormat& format) const { + const Clipboard::FormatType& format) const { FORMATETC format_etc = format.ToFormatEtc(); return (source_object_->QueryGetData(&format_etc) == S_OK); } @@ -892,7 +894,7 @@ ULONG DataObjectImpl::Release() { static STGMEDIUM* GetStorageForBytes(const void* data, size_t bytes) { HANDLE handle = GlobalAlloc(GPTR, static_cast<int>(bytes)); if (handle) { - base::win::ScopedHGlobal<uint8*> scoped(handle); + base::win::ScopedHGlobal<uint8_t*> scoped(handle); memcpy(scoped.get(), data, bytes); } diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h index 21304e58a5c..282585460a1 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h @@ -7,6 +7,7 @@ #include <objidl.h> #include <shlobj.h> +#include <stddef.h> #include <string> #include <vector> @@ -18,6 +19,7 @@ #define IDataObjectAsyncCapability IAsyncOperation #endif +#include "base/macros.h" #include "base/memory/scoped_vector.h" #include "base/win/scoped_comptr.h" #include "ui/base/dragdrop/os_exchange_data.h" @@ -151,7 +153,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderWin void SetURL(const GURL& url, const base::string16& title) override; void SetFilename(const base::FilePath& path) override; void SetFilenames(const std::vector<FileInfo>& filenames) override; - void SetPickledData(const OSExchangeData::CustomFormat& format, + void SetPickledData(const Clipboard::FormatType& format, const base::Pickle& data) override; void SetFileContents(const base::FilePath& filename, const std::string& file_contents) override; @@ -163,7 +165,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderWin base::string16* title) const override; bool GetFilename(base::FilePath* path) const override; bool GetFilenames(std::vector<FileInfo>* filenames) const override; - bool GetPickledData(const OSExchangeData::CustomFormat& format, + bool GetPickledData(const Clipboard::FormatType& format, base::Pickle* data) const override; bool GetFileContents(base::FilePath* filename, std::string* file_contents) const override; @@ -173,8 +175,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderWin bool HasFile() const override; bool HasFileContents() const override; bool HasHtml() const override; - bool HasCustomFormat( - const OSExchangeData::CustomFormat& format) const override; + bool HasCustomFormat(const Clipboard::FormatType& format) const override; void SetDownloadFileInfo( const OSExchangeData::DownloadFileInfo& download_info) override; void SetDragImage(const gfx::ImageSkia& image, diff --git a/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc b/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc index e3fc6b53646..ca8e9203305 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc @@ -6,6 +6,7 @@ #include "base/message_loop/message_loop.h" #include "base/pickle.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" #include "net/base/filename_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -144,8 +145,8 @@ TEST_F(OSExchangeDataTest, TestFileToURLConversion) { } TEST_F(OSExchangeDataTest, TestPickledData) { - const OSExchangeData::CustomFormat kTestFormat = - ui::Clipboard::GetFormatType("application/vnd.chromium.test"); + const Clipboard::FormatType kTestFormat = + Clipboard::GetFormatType("application/vnd.chromium.test"); base::Pickle saved_pickle; saved_pickle.WriteInt(1); diff --git a/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc b/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc index 010430709a5..1db2c1642b4 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc @@ -193,7 +193,7 @@ TEST(OSExchangeDataWinTest, EnumerationViaCOM) { FORMATETC elements_array[1]; EXPECT_EQ(S_OK, enumerator->Next(1, reinterpret_cast<FORMATETC*>(&elements_array), &retrieved)); - EXPECT_EQ(1, retrieved); + EXPECT_EQ(1u, retrieved); EXPECT_EQ(text_x_moz_url, elements_array[0].cfFormat); } @@ -213,7 +213,7 @@ TEST(OSExchangeDataWinTest, EnumerationViaCOM) { FORMATETC elements_array[2]; EXPECT_EQ(S_OK, enumerator->Next(2, reinterpret_cast<FORMATETC*>(&elements_array), &retrieved)); - EXPECT_EQ(2, retrieved); + EXPECT_EQ(2u, retrieved); EXPECT_EQ(text_x_moz_url, elements_array[0].cfFormat); EXPECT_EQ(cfstr_file_group_descriptor, elements_array[1].cfFormat); } @@ -226,7 +226,7 @@ TEST(OSExchangeDataWinTest, EnumerationViaCOM) { FORMATETC elements_array[1]; EXPECT_EQ(S_OK, enumerator->Next(1, reinterpret_cast<FORMATETC*>(&elements_array), &retrieved)); - EXPECT_EQ(1, retrieved); + EXPECT_EQ(1u, retrieved); EXPECT_EQ(cfstr_file_group_descriptor, elements_array[0].cfFormat); } @@ -244,7 +244,7 @@ TEST(OSExchangeDataWinTest, EnumerationViaCOM) { FORMATETC elements_array[1]; EXPECT_EQ(S_OK, cloned_enumerator->Next(1, reinterpret_cast<FORMATETC*>(&elements_array), &retrieved)); - EXPECT_EQ(1, retrieved); + EXPECT_EQ(1u, retrieved); EXPECT_EQ(cfstr_file_group_descriptor, elements_array[0].cfFormat); } @@ -253,7 +253,7 @@ TEST(OSExchangeDataWinTest, EnumerationViaCOM) { FORMATETC elements_array[1]; EXPECT_EQ(S_OK, enumerator->Next(1, reinterpret_cast<FORMATETC*>(&elements_array), &retrieved)); - EXPECT_EQ(1, retrieved); + EXPECT_EQ(1u, retrieved); EXPECT_EQ(text_x_moz_url, elements_array[0].cfFormat); } } diff --git a/chromium/ui/base/hit_test.h b/chromium/ui/base/hit_test.h index a91ce892ce1..45ad59ff62e 100644 --- a/chromium/ui/base/hit_test.h +++ b/chromium/ui/base/hit_test.h @@ -5,6 +5,8 @@ #ifndef UI_BASE_HIT_TEST_H_ #define UI_BASE_HIT_TEST_H_ +#include "build/build_config.h" + #if !defined(OS_WIN) // Defines the same symbolic names used by the WM_NCHITTEST Notification under diff --git a/chromium/ui/base/idle/idle.h b/chromium/ui/base/idle/idle.h index 7ecdbff9a6b..9ea9f439fb8 100644 --- a/chromium/ui/base/idle/idle.h +++ b/chromium/ui/base/idle/idle.h @@ -6,6 +6,7 @@ #define UI_BASE_IDLE_IDLE_H_ #include "base/callback.h" +#include "build/build_config.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/idle/idle_android.cc b/chromium/ui/base/idle/idle_android.cc new file mode 100644 index 00000000000..43b27c019d3 --- /dev/null +++ b/chromium/ui/base/idle/idle_android.cc @@ -0,0 +1,21 @@ +// Copyright 2015 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/base/idle/idle.h" + +#include "base/logging.h" + +namespace ui { + +void CalculateIdleTime(IdleTimeCallback notify) { + NOTIMPLEMENTED(); + notify.Run(0); +} + +bool CheckIdleStateIsLocked() { + NOTIMPLEMENTED(); + return false; +} + +} // namespace ui diff --git a/chromium/ui/base/idle/idle_linux.cc b/chromium/ui/base/idle/idle_linux.cc index 622ae8d07ec..a35aca72ee9 100644 --- a/chromium/ui/base/idle/idle_linux.cc +++ b/chromium/ui/base/idle/idle_linux.cc @@ -4,7 +4,6 @@ #include "ui/base/idle/idle.h" -#include "base/basictypes.h" #if defined(USE_X11) #include "ui/base/idle/idle_query_x11.h" diff --git a/chromium/ui/base/idle/idle_query_x11.h b/chromium/ui/base/idle/idle_query_x11.h index 56588e60f3f..e5f6b96cbd1 100644 --- a/chromium/ui/base/idle/idle_query_x11.h +++ b/chromium/ui/base/idle/idle_query_x11.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_IDLE_IDLE_QUERY_X11_H_ #define UI_BASE_IDLE_IDLE_QUERY_X11_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" namespace ui { diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.cc b/chromium/ui/base/idle/screensaver_window_finder_x11.cc index b6e3be28907..e5ddd3013a3 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.cc +++ b/chromium/ui/base/idle/screensaver_window_finder_x11.cc @@ -4,7 +4,6 @@ #include "ui/base/idle/screensaver_window_finder_x11.h" -#include "base/basictypes.h" #include "ui/base/x/x11_util.h" #include "ui/gfx/x/x11_error_tracker.h" diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.h b/chromium/ui/base/idle/screensaver_window_finder_x11.h index 1383b597d99..dad3d209510 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.h +++ b/chromium/ui/base/idle/screensaver_window_finder_x11.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ #define UI_BASE_IDLE_SCREENSAVER_WINDOW_FINDER_X11_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/x/x11_util.h" namespace ui { diff --git a/chromium/ui/base/ime/BUILD.gn b/chromium/ui/base/ime/BUILD.gn index fc938a3bcae..b915757c0d4 100644 --- a/chromium/ui/base/ime/BUILD.gn +++ b/chromium/ui/base/ime/BUILD.gn @@ -14,16 +14,13 @@ component("ime") { "chromeos/character_composer.h", "chromeos/component_extension_ime_manager.cc", "chromeos/component_extension_ime_manager.h", - "chromeos/composition_text_chromeos.cc", - "chromeos/composition_text_chromeos.h", "chromeos/extension_ime_util.cc", "chromeos/extension_ime_util.h", "chromeos/fake_ime_keyboard.cc", "chromeos/fake_ime_keyboard.h", "chromeos/fake_input_method_delegate.cc", "chromeos/fake_input_method_delegate.h", - "chromeos/ime_bridge.cc", - "chromeos/ime_bridge.h", + "chromeos/ime_candidate_window_handler_interface.h", "chromeos/ime_keyboard.cc", "chromeos/ime_keyboard.h", "chromeos/ime_keyboard_ozone.cc", @@ -52,6 +49,12 @@ component("ime") { "composition_text_util_pango.cc", "composition_text_util_pango.h", "composition_underline.h", + "ime_bridge.cc", + "ime_bridge.h", + "ime_engine_handler_interface.cc", + "ime_engine_handler_interface.h", + "ime_engine_observer.h", + "ime_input_context_handler_interface.h", "infolist_entry.cc", "infolist_entry.h", "input_method.h", @@ -102,8 +105,8 @@ component("ime") { deps = [ "//base", - "//base/third_party/dynamic_annotations", "//base:i18n", + "//base/third_party/dynamic_annotations", "//net", "//third_party/icu", "//ui/base", @@ -120,6 +123,13 @@ component("ime") { ] } + if (use_aura && is_android) { + sources += [ + "input_method_android.cc", + "input_method_android.h", + ] + } + if (!toolkit_views && !use_aura) { sources -= [ "input_method_factory.cc", @@ -171,8 +181,8 @@ component("ime") { if (use_ozone) { deps += [ - "//ui/ozone", "//ui/events/ozone:events_ozone_layout", + "//ui/ozone", ] } } diff --git a/chromium/ui/base/ime/candidate_window.cc b/chromium/ui/base/ime/candidate_window.cc index 6cb32e2d77f..60f8c4d7c33 100644 --- a/chromium/ui/base/ime/candidate_window.cc +++ b/chromium/ui/base/ime/candidate_window.cc @@ -4,6 +4,8 @@ #include "ui/base/ime/candidate_window.h" +#include <stddef.h> + #include <string> #include "base/logging.h" #include "base/strings/utf_string_conversions.h" diff --git a/chromium/ui/base/ime/candidate_window.h b/chromium/ui/base/ime/candidate_window.h index f8c967e6d69..ad52c33e309 100644 --- a/chromium/ui/base/ime/candidate_window.h +++ b/chromium/ui/base/ime/candidate_window.h @@ -5,9 +5,12 @@ #ifndef UI_BASE_IME_CANDIDATE_WINDOW_H_ #define UI_BASE_IME_CANDIDATE_WINDOW_H_ +#include <stdint.h> + #include <string> #include <vector> -#include "base/basictypes.h" + +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "ui/base/ime/infolist_entry.h" #include "ui/base/ime/ui_base_ime_export.h" @@ -70,12 +73,12 @@ class UI_BASE_IME_EXPORT CandidateWindow { bool* has_highlighted) const; // Returns the number of candidates in one page. - uint32 page_size() const { return property_->page_size; } - void set_page_size(uint32 page_size) { property_->page_size = page_size; } + uint32_t page_size() const { return property_->page_size; } + void set_page_size(uint32_t page_size) { property_->page_size = page_size; } // Returns the cursor index of the currently selected candidate. - uint32 cursor_position() const { return property_->cursor_position; } - void set_cursor_position(uint32 cursor_position) { + uint32_t cursor_position() const { return property_->cursor_position; } + void set_cursor_position(uint32_t cursor_position) { property_->cursor_position = cursor_position; } diff --git a/chromium/ui/base/ime/candidate_window_unittest.cc b/chromium/ui/base/ime/candidate_window_unittest.cc index 4defe56b5e0..60022d29361 100644 --- a/chromium/ui/base/ime/candidate_window_unittest.cc +++ b/chromium/ui/base/ime/candidate_window_unittest.cc @@ -5,6 +5,8 @@ #include "ui/base/ime/candidate_window.h" +#include <stddef.h> + #include <string> #include "base/compiler_specific.h" diff --git a/chromium/ui/base/ime/composition_text.cc b/chromium/ui/base/ime/composition_text.cc index f85bc748758..d3ae7f3a399 100644 --- a/chromium/ui/base/ime/composition_text.cc +++ b/chromium/ui/base/ime/composition_text.cc @@ -18,4 +18,13 @@ void CompositionText::Clear() { selection = gfx::Range(); } +void CompositionText::CopyFrom(const CompositionText& obj) { + Clear(); + text = obj.text; + for (size_t i = 0; i < obj.underlines.size(); i++) { + underlines.push_back(obj.underlines[i]); + } + selection = obj.selection; +} + } // namespace ui diff --git a/chromium/ui/base/ime/composition_text.h b/chromium/ui/base/ime/composition_text.h index 063592e11aa..9b729b502ba 100644 --- a/chromium/ui/base/ime/composition_text.h +++ b/chromium/ui/base/ime/composition_text.h @@ -5,6 +5,8 @@ #ifndef UI_BASE_IME_COMPOSITION_TEXT_H_ #define UI_BASE_IME_COMPOSITION_TEXT_H_ +#include <stddef.h> + #include "base/strings/string16.h" #include "ui/base/ime/composition_underline.h" #include "ui/base/ime/ui_base_ime_export.h" @@ -35,6 +37,8 @@ struct UI_BASE_IME_EXPORT CompositionText { void Clear(); + void CopyFrom(const CompositionText& obj); + // Content of the composition text. base::string16 text; diff --git a/chromium/ui/base/ime/composition_text_unittest.cc b/chromium/ui/base/ime/composition_text_unittest.cc new file mode 100644 index 00000000000..c03090a5623 --- /dev/null +++ b/chromium/ui/base/ime/composition_text_unittest.cc @@ -0,0 +1,53 @@ +// Copyright 2015 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/base/ime/composition_text.h" + +#include <stddef.h> + +#include "base/strings/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace ui { + +TEST(CompositionTextTest, CopyTest) { + const base::string16 kSampleText = base::UTF8ToUTF16("Sample Text"); + const CompositionUnderline kSampleUnderline1(10, 20, SK_ColorBLACK, false, + SK_ColorTRANSPARENT); + + const CompositionUnderline kSampleUnderline2(11, 21, SK_ColorBLACK, true, + SK_ColorTRANSPARENT); + + const CompositionUnderline kSampleUnderline3(12, 22, SK_ColorRED, false, + SK_ColorTRANSPARENT); + + // Make CompositionText + CompositionText text; + text.text = kSampleText; + text.underlines.push_back(kSampleUnderline1); + text.underlines.push_back(kSampleUnderline2); + text.underlines.push_back(kSampleUnderline3); + text.selection.set_start(30); + text.selection.set_end(40); + + CompositionText text2; + text2.CopyFrom(text); + + EXPECT_EQ(text.text, text2.text); + EXPECT_EQ(text.underlines.size(), text2.underlines.size()); + for (size_t i = 0; i < text.underlines.size(); ++i) { + EXPECT_EQ(text.underlines[i].start_offset, + text2.underlines[i].start_offset); + EXPECT_EQ(text.underlines[i].end_offset, text2.underlines[i].end_offset); + EXPECT_EQ(text.underlines[i].color, text2.underlines[i].color); + EXPECT_EQ(text.underlines[i].thick, text2.underlines[i].thick); + EXPECT_EQ(text.underlines[i].background_color, + text2.underlines[i].background_color); + } + + EXPECT_EQ(text.selection.start(), text2.selection.start()); + EXPECT_EQ(text.selection.end(), text2.selection.end()); +} + +} // namespace ui diff --git a/chromium/ui/base/ime/composition_text_util_pango.cc b/chromium/ui/base/ime/composition_text_util_pango.cc index 325cdd61d92..b8a92973992 100644 --- a/chromium/ui/base/ime/composition_text_util_pango.cc +++ b/chromium/ui/base/ime/composition_text_util_pango.cc @@ -5,8 +5,8 @@ #include "ui/base/ime/composition_text_util_pango.h" #include <pango/pango-attributes.h> +#include <stddef.h> -#include "base/basictypes.h" #include "base/i18n/char_iterator.h" #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" diff --git a/chromium/ui/base/ime/composition_text_util_pango_unittest.cc b/chromium/ui/base/ime/composition_text_util_pango_unittest.cc index a2056cfc0e9..c645e300da8 100644 --- a/chromium/ui/base/ime/composition_text_util_pango_unittest.cc +++ b/chromium/ui/base/ime/composition_text_util_pango_unittest.cc @@ -5,12 +5,14 @@ #include "ui/base/ime/composition_text_util_pango.h" #include <pango/pango-attributes.h> +#include <stddef.h> +#include <stdint.h> #include <string> #include <utility> -#include "base/basictypes.h" #include "base/logging.h" +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/ime/composition_text.h" @@ -26,9 +28,9 @@ struct AttributeInfo { struct Underline { unsigned start_offset; unsigned end_offset; - uint32 color; + uint32_t color; bool thick; - uint32 background_color; + uint32_t background_color; }; struct TestData { diff --git a/chromium/ui/base/ime/composition_underline.h b/chromium/ui/base/ime/composition_underline.h index a8c44b66854..f81706950b0 100644 --- a/chromium/ui/base/ime/composition_underline.h +++ b/chromium/ui/base/ime/composition_underline.h @@ -5,9 +5,10 @@ #ifndef UI_BASE_IME_COMPOSITION_UNDERLINE_H_ #define UI_BASE_IME_COMPOSITION_UNDERLINE_H_ +#include <stdint.h> + #include <vector> -#include "base/basictypes.h" #include "third_party/skia/include/core/SkColor.h" namespace ui { @@ -23,14 +24,14 @@ struct CompositionUnderline { background_color(SK_ColorTRANSPARENT) {} // TODO(huangs): remove this constructor. - CompositionUnderline(uint32 s, uint32 e, SkColor c, bool t) + CompositionUnderline(uint32_t s, uint32_t e, SkColor c, bool t) : start_offset(s), end_offset(e), color(c), thick(t), background_color(SK_ColorTRANSPARENT) {} - CompositionUnderline(uint32 s, uint32 e, SkColor c, bool t, SkColor bc) + CompositionUnderline(uint32_t s, uint32_t e, SkColor c, bool t, SkColor bc) : start_offset(s), end_offset(e), color(c), @@ -48,8 +49,8 @@ struct CompositionUnderline { return !(*this == rhs); } - uint32 start_offset; - uint32 end_offset; + uint32_t start_offset; + uint32_t end_offset; SkColor color; bool thick; SkColor background_color; diff --git a/chromium/ui/base/ime/dummy_input_method.h b/chromium/ui/base/ime/dummy_input_method.h index 636c8bbf581..26e888a4411 100644 --- a/chromium/ui/base/ime/dummy_input_method.h +++ b/chromium/ui/base/ime/dummy_input_method.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_DUMMY_INPUT_METHOD_H_ #define UI_BASE_IME_DUMMY_INPUT_METHOD_H_ +#include "base/macros.h" #include "ui/base/ime/input_method.h" namespace ui { diff --git a/chromium/ui/base/ime/dummy_text_input_client.cc b/chromium/ui/base/ime/dummy_text_input_client.cc index c660bd9269b..478b489b4c8 100644 --- a/chromium/ui/base/ime/dummy_text_input_client.cc +++ b/chromium/ui/base/ime/dummy_text_input_client.cc @@ -29,8 +29,7 @@ void DummyTextInputClient::ClearCompositionText() { void DummyTextInputClient::InsertText(const base::string16& text) { } -void DummyTextInputClient::InsertChar(base::char16 ch, int flags) { -} +void DummyTextInputClient::InsertChar(const KeyEvent& event) {} TextInputType DummyTextInputClient::GetTextInputType() const { return text_input_type_; @@ -53,7 +52,7 @@ gfx::Rect DummyTextInputClient::GetCaretBounds() const { } bool DummyTextInputClient::GetCompositionCharacterBounds( - uint32 index, + uint32_t index, gfx::Rect* rect) const { return false; } diff --git a/chromium/ui/base/ime/dummy_text_input_client.h b/chromium/ui/base/ime/dummy_text_input_client.h index 2c26f89eca7..3c5178215db 100644 --- a/chromium/ui/base/ime/dummy_text_input_client.h +++ b/chromium/ui/base/ime/dummy_text_input_client.h @@ -5,6 +5,10 @@ #ifndef UI_BASE_IME_DUMMY_TEXT_INPUT_CLIENT_H_ #define UI_BASE_IME_DUMMY_TEXT_INPUT_CLIENT_H_ +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "ui/base/ime/text_input_client.h" namespace ui { @@ -21,13 +25,13 @@ class DummyTextInputClient : public TextInputClient { void ConfirmCompositionText() override; void ClearCompositionText() override; void InsertText(const base::string16& text) override; - void InsertChar(base::char16 ch, int flags) override; + void InsertChar(const KeyEvent& event) override; TextInputType GetTextInputType() const override; TextInputMode GetTextInputMode() const override; int GetTextInputFlags() const override; bool CanComposeInline() const override; gfx::Rect GetCaretBounds() const override; - bool GetCompositionCharacterBounds(uint32 index, + bool GetCompositionCharacterBounds(uint32_t index, gfx::Rect* rect) const override; bool HasCompositionText() const override; bool GetTextRange(gfx::Range* range) const override; diff --git a/chromium/ui/base/ime/ime_bridge.cc b/chromium/ui/base/ime/ime_bridge.cc new file mode 100644 index 00000000000..7b4e8e23638 --- /dev/null +++ b/chromium/ui/base/ime/ime_bridge.cc @@ -0,0 +1,122 @@ +// Copyright 2014 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/base/ime/ime_bridge.h" + +#include <map> + +#include "base/logging.h" +#include "base/macros.h" +#include "base/memory/singleton.h" +#include "build/build_config.h" + +namespace ui { + +static IMEBridge* g_ime_bridge = NULL; + +// An implementation of IMEBridge. +class IMEBridgeImpl : public IMEBridge { + public: +#if defined(OS_CHROMEOS) + IMEBridgeImpl() + : input_context_handler_(NULL), + engine_handler_(NULL), + current_input_context_(ui::TEXT_INPUT_TYPE_NONE, + ui::TEXT_INPUT_MODE_DEFAULT, + 0), + candidate_window_handler_(NULL) {} +#else + IMEBridgeImpl() + : input_context_handler_(NULL), + engine_handler_(NULL), + current_input_context_(ui::TEXT_INPUT_TYPE_NONE, + ui::TEXT_INPUT_MODE_DEFAULT, + 0) {} +#endif + + ~IMEBridgeImpl() override {} + + // IMEBridge override. + IMEInputContextHandlerInterface* GetInputContextHandler() const override { + return input_context_handler_; + } + + // IMEBridge override. + void SetInputContextHandler( + IMEInputContextHandlerInterface* handler) override { + input_context_handler_ = handler; + } + + // IMEBridge override. + void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) override { + engine_handler_ = handler; + } + + // IMEBridge override. + IMEEngineHandlerInterface* GetCurrentEngineHandler() const override { + return engine_handler_; + } + + // IMEBridge override. + void SetCurrentInputContext( + const IMEEngineHandlerInterface::InputContext& input_context) override { + current_input_context_ = input_context; + } + + // IMEBridge override. + const IMEEngineHandlerInterface::InputContext& GetCurrentInputContext() + const override { + return current_input_context_; + } + +#if defined(OS_CHROMEOS) + // IMEBridge override. + void SetCandidateWindowHandler( + chromeos::IMECandidateWindowHandlerInterface* handler) override { + candidate_window_handler_ = handler; + } + + // IMEBridge override. + chromeos::IMECandidateWindowHandlerInterface* GetCandidateWindowHandler() + const override { + return candidate_window_handler_; + } +#endif + + private: + IMEInputContextHandlerInterface* input_context_handler_; + IMEEngineHandlerInterface* engine_handler_; + IMEEngineHandlerInterface::InputContext current_input_context_; + +#if defined(OS_CHROMEOS) + chromeos::IMECandidateWindowHandlerInterface* candidate_window_handler_; +#endif + + DISALLOW_COPY_AND_ASSIGN(IMEBridgeImpl); +}; + +/////////////////////////////////////////////////////////////////////////////// +// IMEBridge +IMEBridge::IMEBridge() {} + +IMEBridge::~IMEBridge() {} + +// static. +void IMEBridge::Initialize() { + if (!g_ime_bridge) + g_ime_bridge = new IMEBridgeImpl(); +} + +// static. +void IMEBridge::Shutdown() { + delete g_ime_bridge; + g_ime_bridge = NULL; +} + +// static. +IMEBridge* IMEBridge::Get() { + return g_ime_bridge; +} + +} // namespace ui diff --git a/chromium/ui/base/ime/ime_bridge.h b/chromium/ui/base/ime/ime_bridge.h new file mode 100644 index 00000000000..5db8bbaa19f --- /dev/null +++ b/chromium/ui/base/ime/ime_bridge.h @@ -0,0 +1,87 @@ +// Copyright 2014 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_BASE_IME_IME_BRIDGE_H_ +#define UI_BASE_IME_IME_BRIDGE_H_ + +#include "base/macros.h" +#include "build/build_config.h" +#include "ui/base/ime/ime_engine_handler_interface.h" +#include "ui/base/ime/ime_input_context_handler_interface.h" +#include "ui/base/ime/ui_base_ime_export.h" + +#if defined(OS_CHROMEOS) +#include "ui/base/ime/chromeos/ime_candidate_window_handler_interface.h" + +namespace chromeos { +class IMECandidateWindowHandlerInterface; +} +#endif + +namespace ui { + +// IMEBridge provides access of each IME related handler. This class +// is used for IME implementation. +class UI_BASE_IME_EXPORT IMEBridge { + public: + virtual ~IMEBridge(); + + // Allocates the global instance. Must be called before any calls to Get(). + static void Initialize(); + + // Releases the global instance. + static void Shutdown(); + + // Returns IMEBridge global instance. Initialize() must be called first. + static IMEBridge* Get(); + + // Returns current InputContextHandler. This function returns NULL if input + // context is not ready to use. + virtual IMEInputContextHandlerInterface* GetInputContextHandler() const = 0; + + // Updates current InputContextHandler. If there is no active input context, + // pass NULL for |handler|. Caller must release |handler|. + virtual void SetInputContextHandler( + IMEInputContextHandlerInterface* handler) = 0; + + // Updates current EngineHandler. If there is no active engine service, pass + // NULL for |handler|. Caller must release |handler|. + virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) = 0; + + // Returns current EngineHandler. This function returns NULL if current engine + // is not ready to use. + virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const = 0; + + // Updates the current input context. + // This is called from InputMethodChromeOS. + virtual void SetCurrentInputContext( + const IMEEngineHandlerInterface::InputContext& input_context) = 0; + + // Returns the current input context. + // This is called from InputMethodEngine. + virtual const IMEEngineHandlerInterface::InputContext& + GetCurrentInputContext() const = 0; + +#if defined(OS_CHROMEOS) + // Returns current CandidateWindowHandler. This function returns NULL if + // current candidate window is not ready to use. + virtual chromeos::IMECandidateWindowHandlerInterface* + GetCandidateWindowHandler() const = 0; + + // Updates current CandidatWindowHandler. If there is no active candidate + // window service, pass NULL for |handler|. Caller must release |handler|. + virtual void SetCandidateWindowHandler( + chromeos::IMECandidateWindowHandlerInterface* handler) = 0; +#endif + + protected: + IMEBridge(); + + private: + DISALLOW_COPY_AND_ASSIGN(IMEBridge); +}; + +} // namespace ui + +#endif // UI_BASE_IME_IME_BRIDGE_H_ diff --git a/chromium/ui/base/ime/ime_engine_handler_interface.cc b/chromium/ui/base/ime/ime_engine_handler_interface.cc new file mode 100644 index 00000000000..695a547d5fc --- /dev/null +++ b/chromium/ui/base/ime/ime_engine_handler_interface.cc @@ -0,0 +1,44 @@ +// Copyright 2015 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 "build/build_config.h" +#include "ui/base/ime/ime_engine_handler_interface.h" + +namespace ui { + +IMEEngineHandlerInterface::KeyboardEvent::KeyboardEvent() + : alt_key(false), ctrl_key(false), shift_key(false), caps_lock(false) {} + +IMEEngineHandlerInterface::KeyboardEvent::~KeyboardEvent() {} + +// ChromeOS only APIs. +#if defined(OS_CHROMEOS) + +IMEEngineHandlerInterface::MenuItem::MenuItem() {} + +IMEEngineHandlerInterface::MenuItem::~MenuItem() {} + +IMEEngineHandlerInterface::Candidate::Candidate() {} + +IMEEngineHandlerInterface::Candidate::~Candidate() {} + +namespace { +// The default entry number of a page in CandidateWindowProperty. +const int kDefaultPageSize = 9; +} // namespace + +// When the default values are changed, please modify +// CandidateWindow::CandidateWindowProperty defined in chromeos/ime/ too. +IMEEngineHandlerInterface::CandidateWindowProperty::CandidateWindowProperty() + : page_size(kDefaultPageSize), + is_cursor_visible(true), + is_vertical(false), + show_window_at_composition(false) {} + +IMEEngineHandlerInterface::CandidateWindowProperty::~CandidateWindowProperty() { +} + +#endif + +} // namespace ui diff --git a/chromium/ui/base/ime/ime_engine_handler_interface.h b/chromium/ui/base/ime/ime_engine_handler_interface.h new file mode 100644 index 00000000000..6290841b3bd --- /dev/null +++ b/chromium/ui/base/ime/ime_engine_handler_interface.h @@ -0,0 +1,281 @@ +// Copyright 2014 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_BASE_IME_IME_ENGINE_HANDLER_INTERFACE_H_ +#define UI_BASE_IME_IME_ENGINE_HANDLER_INTERFACE_H_ + +#include <stddef.h> +#include <stdint.h> + +#include <string> +#include <vector> + +#include "base/callback.h" +#include "build/build_config.h" +#include "ui/base/ime/text_input_mode.h" +#include "ui/base/ime/text_input_type.h" +#include "ui/base/ime/ui_base_ime_export.h" + +namespace gfx { +class Rect; +} // namespace gfx + +namespace ui { + +class KeyEvent; + +// A interface to handle the engine handler method call. +class UI_BASE_IME_EXPORT IMEEngineHandlerInterface { + public: + typedef base::Callback<void(bool consumed)> KeyEventDoneCallback; + + // A information about a focused text input field. + // A type of each member is based on the html spec, but InputContext can be + // used to specify about a non html text field like Omnibox. + struct InputContext { + InputContext() {} + InputContext(TextInputType type_, TextInputMode mode_, int flags_) + : type(type_), mode(mode_), flags(flags_) {} + InputContext(int id_, TextInputType type_, TextInputMode mode_, int flags_) + : id(id_), type(type_), mode(mode_), flags(flags_) {} + // An attribute of the context id which used for ChromeOS only. + int id; + // An attribute of the field defined at + // http://www.w3.org/TR/html401/interact/forms.html#input-control-types. + TextInputType type; + // An attribute of the field defined at + // http://www.whatwg.org/specs/web-apps/current-work/multipage/ + // association-of-controls-and-forms.html#input-modalities + // :-the-inputmode-attribute. + TextInputMode mode; + // An antribute to indicate the flags for web input fields. Please refer to + // WebTextInputType. + int flags; + }; + + struct KeyboardEvent { + KeyboardEvent(); + virtual ~KeyboardEvent(); + + std::string type; + std::string key; + std::string code; + int key_code; // only used by on-screen keyboards. + std::string extension_id; + bool alt_key; + bool ctrl_key; + bool shift_key; + bool caps_lock; + }; + + enum SegmentStyle { + SEGMENT_STYLE_UNDERLINE, + SEGMENT_STYLE_DOUBLE_UNDERLINE, + SEGMENT_STYLE_NO_UNDERLINE, + }; + + struct SegmentInfo { + int start; + int end; + SegmentStyle style; + }; + + virtual ~IMEEngineHandlerInterface() {} + + // Called when the Chrome input field get the focus. + virtual void FocusIn(const InputContext& input_context) = 0; + + // Called when the Chrome input field lose the focus. + virtual void FocusOut() = 0; + + // Called when the IME is enabled. + virtual void Enable(const std::string& component_id) = 0; + + // Called when the IME is disabled. + virtual void Disable() = 0; + + // Called when the IME is reset. + virtual void Reset() = 0; + + // Called when the key event is received. + // Actual implementation must call |callback| after key event handling. + virtual void ProcessKeyEvent(const KeyEvent& key_event, + KeyEventDoneCallback& callback) = 0; + + // Called when a new surrounding text is set. The |text| is surrounding text + // and |cursor_pos| is 0 based index of cursor position in |text|. If there is + // selection range, |anchor_pos| represents opposite index from |cursor_pos|. + // Otherwise |anchor_pos| is equal to |cursor_pos|. If not all surrounding + // text is given |offset_pos| indicates the starting offset of |text|. + virtual void SetSurroundingText(const std::string& text, + uint32_t cursor_pos, + uint32_t anchor_pos, + uint32_t offset_pos) = 0; + + // Called when the composition bounds changed. + virtual void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) = 0; + + // Returns whether the engine is interested in key events. + // If not, InputMethodChromeOS won't feed it with key events. + virtual bool IsInterestedInKeyEvent() const = 0; + + // Set the current composition and associated properties. + virtual bool SetComposition(int context_id, + const char* text, + int selection_start, + int selection_end, + int cursor, + const std::vector<SegmentInfo>& segments, + std::string* error) = 0; + + // Clear the current composition. + virtual bool ClearComposition(int context_id, std::string* error) = 0; + + // Commit the specified text to the specified context. Fails if the context + // is not focused. + virtual bool CommitText(int context_id, + const char* text, + std::string* error) = 0; + + // Send the sequence of key events. + virtual bool SendKeyEvents(int context_id, + const std::vector<KeyboardEvent>& events) = 0; + + // Returns true if this IME is active, false if not. + virtual bool IsActive() const = 0; + + // Returns the current active input_component id. + virtual const std::string& GetActiveComponentId() const = 0; + + // Deletes |number_of_chars| unicode characters as the basis of |offset| from + // the surrounding text. The |offset| is relative position based on current + // caret. + // NOTE: Currently we are falling back to backspace forwarding workaround, + // because delete_surrounding_text is not supported in Chrome. So this + // function is restricted for only preceding text. + // TODO(nona): Support full spec delete surrounding text. + virtual bool DeleteSurroundingText(int context_id, + int offset, + size_t number_of_chars, + std::string* error) = 0; + +// ChromeOS only APIs. +#if defined(OS_CHROMEOS) + + enum { + MENU_ITEM_MODIFIED_LABEL = 0x0001, + MENU_ITEM_MODIFIED_STYLE = 0x0002, + MENU_ITEM_MODIFIED_VISIBLE = 0x0004, + MENU_ITEM_MODIFIED_ENABLED = 0x0008, + MENU_ITEM_MODIFIED_CHECKED = 0x0010, + MENU_ITEM_MODIFIED_ICON = 0x0020, + }; + + enum MenuItemStyle { + MENU_ITEM_STYLE_NONE, + MENU_ITEM_STYLE_CHECK, + MENU_ITEM_STYLE_RADIO, + MENU_ITEM_STYLE_SEPARATOR, + }; + + enum CandidateWindowPosition { + WINDOW_POS_CURSOR, + WINDOW_POS_COMPOSITTION, + }; + + struct MenuItem { + MenuItem(); + virtual ~MenuItem(); + + std::string id; + std::string label; + MenuItemStyle style; + bool visible; + bool enabled; + bool checked; + + unsigned int modified; + std::vector<MenuItem> children; + }; + + struct UsageEntry { + std::string title; + std::string body; + }; + + struct Candidate { + Candidate(); + virtual ~Candidate(); + + std::string value; + int id; + std::string label; + std::string annotation; + UsageEntry usage; + std::vector<Candidate> candidates; + }; + + struct CandidateWindowProperty { + CandidateWindowProperty(); + virtual ~CandidateWindowProperty(); + int page_size; + bool is_cursor_visible; + bool is_vertical; + bool show_window_at_composition; + + // Auxiliary text is typically displayed in the footer of the candidate + // window. + std::string auxiliary_text; + bool is_auxiliary_text_visible; + }; + + // Called when a property is activated or changed. + virtual void PropertyActivate(const std::string& property_name) = 0; + + // Called when the candidate in lookup table is clicked. The |index| is 0 + // based candidate index in lookup table. + virtual void CandidateClicked(uint32_t index) = 0; + + // This function returns the current property of the candidate window. + // The caller can use the returned value as the default property and + // modify some of specified items. + virtual const CandidateWindowProperty& GetCandidateWindowProperty() const = 0; + + // Change the property of the candidate window and repaint the candidate + // window widget. + virtual void SetCandidateWindowProperty( + const CandidateWindowProperty& property) = 0; + + // Show or hide the candidate window. + virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0; + + // Set the list of entries displayed in the candidate window. + virtual bool SetCandidates(int context_id, + const std::vector<Candidate>& candidates, + std::string* error) = 0; + + // Set the position of the cursor in the candidate window. + virtual bool SetCursorPosition(int context_id, + int candidate_id, + std::string* error) = 0; + + // Set the list of items that appears in the language menu when this IME is + // active. + virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0; + + // Update the state of the menu items. + virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0; + + // Hides the input view window (from API call). + virtual void HideInputView() = 0; + +#endif // defined(OS_CHROMEOS) + + protected: + IMEEngineHandlerInterface() {} +}; + +} // namespace ui + +#endif // UI_BASE_IME_IME_ENGINE_HANDLER_INTERFACE_H_ diff --git a/chromium/ui/base/ime/ime_engine_observer.h b/chromium/ui/base/ime/ime_engine_observer.h new file mode 100644 index 00000000000..7a2bf9d2682 --- /dev/null +++ b/chromium/ui/base/ime/ime_engine_observer.h @@ -0,0 +1,81 @@ +// Copyright 2015 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_BASE_IME_IME_ENGINE_OBSERVER_H_ +#define UI_BASE_IME_IME_ENGINE_OBSERVER_H_ + +#include "build/build_config.h" +#include "ui/base/ime/ime_engine_handler_interface.h" + +namespace ui { + +class IMEEngineObserver { + public: + virtual ~IMEEngineObserver() {} + + // Called when the IME becomes the active IME. + virtual void OnActivate(const std::string& engine_id) = 0; + + // Called when a text field gains focus, and will be sending key events. + virtual void OnFocus( + const IMEEngineHandlerInterface::InputContext& context) = 0; + + // Called when a text field loses focus, and will no longer generate events. + virtual void OnBlur(int context_id) = 0; + + // Called when the user pressed a key with a text field focused. + virtual void OnKeyEvent( + const std::string& engine_id, + const IMEEngineHandlerInterface::KeyboardEvent& event, + IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) = 0; + + // Called when Chrome terminates on-going text input session. + virtual void OnReset(const std::string& engine_id) = 0; + + // Called when the IME is no longer active. + virtual void OnDeactivated(const std::string& engine_id) = 0; + + // Called when composition bounds are changed. + virtual void OnCompositionBoundsChanged( + const std::vector<gfx::Rect>& bounds) = 0; + + // Returns whether the observer is interested in key events. + virtual bool IsInterestedInKeyEvent() const = 0; + + // Called when a surrounding text is changed. + virtual void OnSurroundingTextChanged(const std::string& engine_id, + const std::string& text, + int cursor_pos, + int anchor_pos, + int offset_pos) = 0; + +// ChromeOS only APIs. +#if defined(OS_CHROMEOS) + + enum MouseButtonEvent { + MOUSE_BUTTON_LEFT, + MOUSE_BUTTON_RIGHT, + MOUSE_BUTTON_MIDDLE, + }; + + // Called when an InputContext's properties change while it is focused. + virtual void OnInputContextUpdate( + const IMEEngineHandlerInterface::InputContext& context) = 0; + + + + // Called when the user clicks on an item in the candidate list. + virtual void OnCandidateClicked(const std::string& engine_id, + int candidate_id, + MouseButtonEvent button) = 0; + + // Called when a menu item for this IME is interacted with. + virtual void OnMenuItemActivated(const std::string& engine_id, + const std::string& menu_id) = 0; +#endif +}; + +} // namespace ui + +#endif // UI_BASE_IME_IME_ENGINE_OBSERVER_H_ diff --git a/chromium/ui/base/ime/ime_input_context_handler_interface.h b/chromium/ui/base/ime/ime_input_context_handler_interface.h new file mode 100644 index 00000000000..5a8f6aeae3a --- /dev/null +++ b/chromium/ui/base/ime/ime_input_context_handler_interface.h @@ -0,0 +1,32 @@ +// Copyright 2014 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_BASE_IME_IME_INPUT_CONTEXT_HANDLER_INTERFACE_H_ +#define UI_BASE_IME_IME_INPUT_CONTEXT_HANDLER_INTERFACE_H_ + +#include <stdint.h> + +#include <string> +#include "ui/base/ime/composition_text.h" +#include "ui/base/ime/ui_base_ime_export.h" + +namespace ui { + +class UI_BASE_IME_EXPORT IMEInputContextHandlerInterface { + public: + // Called when the engine commit a text. + virtual void CommitText(const std::string& text) = 0; + + // Called when the engine updates composition text. + virtual void UpdateCompositionText(const CompositionText& text, + uint32_t cursor_pos, + bool visible) = 0; + + // Called when the engine request deleting surrounding string. + virtual void DeleteSurroundingText(int32_t offset, uint32_t length) = 0; +}; + +} // namespace ui + +#endif // UI_BASE_IME_IME_INPUT_CONTEXT_HANDLER_INTERFACE_H_ diff --git a/chromium/ui/base/ime/input_method.h b/chromium/ui/base/ime/input_method.h index 21b02354b2c..598fd4f76f9 100644 --- a/chromium/ui/base/ime/input_method.h +++ b/chromium/ui/base/ime/input_method.h @@ -5,10 +5,12 @@ #ifndef UI_BASE_IME_INPUT_METHOD_H_ #define UI_BASE_IME_INPUT_METHOD_H_ +#include <stdint.h> + #include <string> -#include "base/basictypes.h" #include "base/event_types.h" +#include "build/build_config.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" @@ -50,7 +52,7 @@ class InputMethod { #if defined(OS_WIN) typedef LRESULT NativeEventResult; #else - typedef int32 NativeEventResult; + typedef int32_t NativeEventResult; #endif virtual ~InputMethod() {} diff --git a/chromium/ui/base/ime/input_method_android.cc b/chromium/ui/base/ime/input_method_android.cc new file mode 100644 index 00000000000..23f3b5090b8 --- /dev/null +++ b/chromium/ui/base/ime/input_method_android.cc @@ -0,0 +1,62 @@ +// Copyright 2015 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/base/ime/input_method_android.h" + +#include "ui/base/ime/text_input_client.h" +#include "ui/events/event.h" + +// TODO(bshe): This is currently very similar to InputMethodMUS. Consider unify +// them in the furture if the two have reasonable similarity. + +namespace ui { + +//////////////////////////////////////////////////////////////////////////////// +// InputMethodAndroid, public: + +InputMethodAndroid::InputMethodAndroid( + internal::InputMethodDelegate* delegate) { + SetDelegate(delegate); +} + +InputMethodAndroid::~InputMethodAndroid() {} + +bool InputMethodAndroid::OnUntranslatedIMEMessage( + const base::NativeEvent& event, + NativeEventResult* result) { + return false; +} + +void InputMethodAndroid::DispatchKeyEvent(ui::KeyEvent* event) { + DCHECK(event->type() == ui::ET_KEY_PRESSED || + event->type() == ui::ET_KEY_RELEASED); + + // If no text input client, do nothing. + if (!GetTextInputClient()) { + ignore_result(DispatchKeyEventPostIME(event)); + return; + } + + ignore_result(DispatchKeyEventPostIME(event)); +} + +void InputMethodAndroid::OnCaretBoundsChanged( + const ui::TextInputClient* client) { +} + +void InputMethodAndroid::CancelComposition( + const ui::TextInputClient* client) { +} + +void InputMethodAndroid::OnInputLocaleChanged() {} + +std::string InputMethodAndroid::GetInputLocale() { + return ""; +} + +bool InputMethodAndroid::IsCandidatePopupOpen() const { + return false; +} + +} // namespace ui diff --git a/chromium/ui/base/ime/input_method_android.h b/chromium/ui/base/ime/input_method_android.h new file mode 100644 index 00000000000..edadf7378d6 --- /dev/null +++ b/chromium/ui/base/ime/input_method_android.h @@ -0,0 +1,36 @@ +// Copyright 2015 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_BASE_IME_INPUT_METHOD_ANDROID_H_ +#define UI_BASE_IME_INPUT_METHOD_ANDROID_H_ + +#include "base/macros.h" +#include "ui/base/ime/input_method_base.h" + +namespace ui { + +// A ui::InputMethod implementation for Aura on Android platform. +class UI_BASE_IME_EXPORT InputMethodAndroid : public InputMethodBase { + public: + explicit InputMethodAndroid(internal::InputMethodDelegate* delegate); + ~InputMethodAndroid() override; + + private: + // Overriden from InputMethod. + bool OnUntranslatedIMEMessage(const base::NativeEvent& event, + NativeEventResult* result) override; + void DispatchKeyEvent(ui::KeyEvent* event) override; + void OnCaretBoundsChanged(const TextInputClient* client) override; + void CancelComposition(const TextInputClient* client) override; + void OnInputLocaleChanged() override; + std::string GetInputLocale() override; + bool IsCandidatePopupOpen() const override; + + DISALLOW_COPY_AND_ASSIGN(InputMethodAndroid); +}; + +} // namespace ui + +#endif // UI_BASE_IME_INPUT_METHOD_ANDROID_H_ + diff --git a/chromium/ui/base/ime/input_method_auralinux.cc b/chromium/ui/base/ime/input_method_auralinux.cc index ade657766e8..ca9931f06f7 100644 --- a/chromium/ui/base/ime/input_method_auralinux.cc +++ b/chromium/ui/base/ime/input_method_auralinux.cc @@ -97,8 +97,11 @@ void InputMethodAuraLinux::DispatchKeyEvent(ui::KeyEvent* event) { // Processes the result text before composition for sync mode. if (client && !result_text_.empty()) { if (filtered && NeedInsertChar()) { - for (const auto ch : result_text_) - client->InsertChar(ch, event->flags()); + for (const auto ch : result_text_) { + ui::KeyEvent ch_event(*event); + ch_event.set_character(ch); + client->InsertChar(ch_event); + } } else { // If |filtered| is false, that means the IME wants to commit some text // but still release the key to the application. For example, Korean IME @@ -146,7 +149,7 @@ void InputMethodAuraLinux::DispatchKeyEvent(ui::KeyEvent* event) { // DispatchKeyEventPostIME may cause the current text input client change. base::char16 ch = event->GetCharacter(); if (ch && GetTextInputClient()) - GetTextInputClient()->InsertChar(ch, event->flags()); + GetTextInputClient()->InsertChar(*event); should_stop_propagation = true; } } diff --git a/chromium/ui/base/ime/input_method_auralinux.h b/chromium/ui/base/ime/input_method_auralinux.h index 05a80d7798b..29b76fdb44f 100644 --- a/chromium/ui/base/ime/input_method_auralinux.h +++ b/chromium/ui/base/ime/input_method_auralinux.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_INPUT_METHOD_AURALINUX_H_ #define UI_BASE_IME_INPUT_METHOD_AURALINUX_H_ +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "ui/base/ime/composition_text.h" #include "ui/base/ime/input_method_base.h" diff --git a/chromium/ui/base/ime/input_method_auralinux_unittest.cc b/chromium/ui/base/ime/input_method_auralinux_unittest.cc index 7716e9ed049..7ed2d49fb62 100644 --- a/chromium/ui/base/ime/input_method_auralinux_unittest.cc +++ b/chromium/ui/base/ime/input_method_auralinux_unittest.cc @@ -4,6 +4,9 @@ #include "ui/base/ime/input_method_auralinux.h" +#include <stddef.h> + +#include "base/macros.h" #include "base/memory/singleton.h" #include "base/strings/string_split.h" #include "base/strings/utf_string_conversions.h" @@ -222,9 +225,9 @@ class TextInputClientForTesting : public DummyTextInputClient { composition_text.clear(); } - void InsertChar(base::char16 ch, int flags) override { + void InsertChar(const ui::KeyEvent& event) override { std::stringstream ss; - ss << ch; + ss << event.GetCharacter(); TestResult::GetInstance()->RecordAction(base::ASCIIToUTF16("keypress:") + base::ASCIIToUTF16(ss.str())); } diff --git a/chromium/ui/base/ime/input_method_base.h b/chromium/ui/base/ime/input_method_base.h index 345683906be..e9efb3a29b9 100644 --- a/chromium/ui/base/ime/input_method_base.h +++ b/chromium/ui/base/ime/input_method_base.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_IME_INPUT_METHOD_BASE_H_ #define UI_BASE_IME_INPUT_METHOD_BASE_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "ui/base/ime/input_method.h" diff --git a/chromium/ui/base/ime/input_method_base_unittest.cc b/chromium/ui/base/ime/input_method_base_unittest.cc index 0b619c2ef55..175f998dc90 100644 --- a/chromium/ui/base/ime/input_method_base_unittest.cc +++ b/chromium/ui/base/ime/input_method_base_unittest.cc @@ -5,6 +5,7 @@ #include "ui/base/ime/input_method_base.h" #include "base/gtest_prod_util.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" diff --git a/chromium/ui/base/ime/input_method_chromeos.cc b/chromium/ui/base/ime/input_method_chromeos.cc index 1665269b1b9..8062a3c6d8c 100644 --- a/chromium/ui/base/ime/input_method_chromeos.cc +++ b/chromium/ui/base/ime/input_method_chromeos.cc @@ -4,12 +4,13 @@ #include "ui/base/ime/input_method_chromeos.h" +#include <stddef.h> + #include <algorithm> #include <cstring> #include <set> #include <vector> -#include "base/basictypes.h" #include "base/bind.h" #include "base/i18n/char_iterator.h" #include "base/logging.h" @@ -17,16 +18,18 @@ #include "base/strings/utf_string_conversions.h" #include "base/sys_info.h" #include "base/third_party/icu/icu_utf.h" -#include "ui/base/ime/chromeos/composition_text_chromeos.h" #include "ui/base/ime/chromeos/ime_keyboard.h" #include "ui/base/ime/chromeos/input_method_manager.h" +#include "ui/base/ime/composition_text.h" +#include "ui/base/ime/ime_bridge.h" +#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/text_input_client.h" #include "ui/events/event.h" #include "ui/gfx/geometry/rect.h" namespace { -chromeos::IMEEngineHandlerInterface* GetEngine() { - return chromeos::IMEBridge::Get()->GetCurrentEngineHandler(); +ui::IMEEngineHandlerInterface* GetEngine() { + return ui::IMEBridge::Get()->GetCurrentEngineHandler(); } } // namespace @@ -40,7 +43,7 @@ InputMethodChromeOS::InputMethodChromeOS( handling_key_event_(false), weak_ptr_factory_(this) { SetDelegate(delegate); - chromeos::IMEBridge::Get()->SetInputContextHandler(this); + ui::IMEBridge::Get()->SetInputContextHandler(this); UpdateContextFocusState(); } @@ -50,8 +53,8 @@ InputMethodChromeOS::~InputMethodChromeOS() { // We are dead, so we need to ask the client to stop relying on us. OnInputMethodChanged(); - if (chromeos::IMEBridge::Get()) - chromeos::IMEBridge::Get()->SetInputContextHandler(NULL); + if (ui::IMEBridge::Get()) + ui::IMEBridge::Get()->SetInputContextHandler(NULL); } void InputMethodChromeOS::OnFocus() { @@ -106,10 +109,8 @@ void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { if (manager) { chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); if (keyboard && event->type() == ui::ET_KEY_PRESSED) { - bool caps = (event->key_code() == ui::VKEY_CAPITAL) - ? !keyboard->CapsLockIsEnabled() - : (event->flags() & EF_CAPS_LOCK_DOWN); - keyboard->SetCapsLockEnabled(caps); + keyboard->SetCapsLockEnabled((event->key_code() == ui::VKEY_CAPITAL) ? + !keyboard->CapsLockIsEnabled() : event->IsCapsLockOn()); } } } @@ -136,12 +137,12 @@ void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { handling_key_event_ = true; if (GetEngine()->IsInterestedInKeyEvent()) { - GetEngine()->ProcessKeyEvent( - *event, + ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = base::Bind(&InputMethodChromeOS::ProcessKeyEventDone, weak_ptr_factory_.GetWeakPtr(), // Pass the ownership of the new copied event. - base::Owned(new ui::KeyEvent(*event)))); + base::Owned(new ui::KeyEvent(*event))); + GetEngine()->ProcessKeyEvent(*event, callback); } else { ProcessKeyEventDone(event, false); } @@ -154,13 +155,13 @@ void InputMethodChromeOS::OnTextInputTypeChanged( UpdateContextFocusState(); - chromeos::IMEEngineHandlerInterface* engine = GetEngine(); + ui::IMEEngineHandlerInterface* engine = GetEngine(); if (engine) { // When focused input client is not changed, a text input type change should // cause blur/focus events to engine. // The focus in to or out from password field should also notify engine. engine->FocusOut(); - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); engine->FocusIn(context); } @@ -185,7 +186,7 @@ void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { gfx::Rect composition_head; std::vector<gfx::Rect> rects; if (client->HasCompositionText()) { - uint32 i = 0; + uint32_t i = 0; gfx::Rect rect; while (client->GetCompositionCharacterBounds(i++, &rect)) rects.push_back(rect); @@ -204,7 +205,7 @@ void InputMethodChromeOS::OnCaretBoundsChanged(const TextInputClient* client) { GetEngine()->SetCompositionBounds(rects); chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (!candidate_window) return; candidate_window->SetCursorBounds(caret_rect, composition_head); @@ -282,7 +283,7 @@ void InputMethodChromeOS::OnDidChangeFocusedClient( UpdateContextFocusState(); if (GetEngine()) { - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); GetEngine()->FocusIn(context); } @@ -324,13 +325,13 @@ void InputMethodChromeOS::UpdateContextFocusState() { // Propagate the focus event to the candidate window handler which also // manages the input method mode indicator. chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (candidate_window) candidate_window->FocusStateChanged(IsNonPasswordInputFieldFocused()); - chromeos::IMEEngineHandlerInterface::InputContext context( + ui::IMEEngineHandlerInterface::InputContext context( GetTextInputType(), GetTextInputMode(), GetTextInputFlags()); - chromeos::IMEBridge::Get()->SetCurrentInputContext(context); + ui::IMEBridge::Get()->SetCurrentInputContext(context); if (!IsTextInputTypeNone()) OnCaretBoundsChanged(GetTextInputClient()); @@ -412,9 +413,9 @@ void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( // If a key event was not filtered by |context_| and |character_composer_|, // then it means the key event didn't generate any result text. So we need // to send corresponding character to the focused text input client. - uint16 ch = event->GetCharacter(); + uint16_t ch = event->GetCharacter(); if (ch) - client->InsertChar(ch, event->flags()); + client->InsertChar(*event); } void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, @@ -426,7 +427,9 @@ void InputMethodChromeOS::ProcessInputMethodResult(ui::KeyEvent* event, if (handled && NeedInsertChar()) { for (base::string16::const_iterator i = result_text_.begin(); i != result_text_.end(); ++i) { - client->InsertChar(*i, event->flags()); + ui::KeyEvent ch_event(*event); + ch_event.set_character(*i); + client->InsertChar(ch_event); } } else { client->InsertText(result_text_); @@ -495,18 +498,17 @@ void InputMethodChromeOS::CommitText(const std::string& text) { } } -void InputMethodChromeOS::UpdateCompositionText( - const chromeos::CompositionText& text, - uint32 cursor_pos, - bool visible) { +void InputMethodChromeOS::UpdateCompositionText(const CompositionText& text, + uint32_t cursor_pos, + bool visible) { if (IsTextInputTypeNone()) return; if (!CanComposeInline()) { chromeos::IMECandidateWindowHandlerInterface* candidate_window = - chromeos::IMEBridge::Get()->GetCandidateWindowHandler(); + ui::IMEBridge::Get()->GetCandidateWindowHandler(); if (candidate_window) - candidate_window->UpdatePreeditText(text.text(), cursor_pos, visible); + candidate_window->UpdatePreeditText(text.text, cursor_pos, visible); } // |visible| argument is very confusing. For example, what's the correct @@ -559,12 +561,13 @@ void InputMethodChromeOS::HidePreeditText() { } } -void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { +void InputMethodChromeOS::DeleteSurroundingText(int32_t offset, + uint32_t length) { if (!composition_.text.empty()) return; // do nothing if there is ongoing composition. if (GetTextInputClient()) { - uint32 before = offset >= 0 ? 0U : static_cast<uint32>(-1 * offset); + uint32_t before = offset >= 0 ? 0U : static_cast<uint32_t>(-1 * offset); GetTextInputClient()->ExtendSelectionAndDelete(before, length - before); } } @@ -574,10 +577,9 @@ bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { return false; // CharacterComposer consumed the key event. Update the composition text. - chromeos::CompositionText preedit; - preedit.set_text(character_composer_.preedit_string()); - UpdateCompositionText(preedit, preedit.text().size(), - !preedit.text().empty()); + CompositionText preedit; + preedit.text = character_composer_.preedit_string(); + UpdateCompositionText(preedit, preedit.text.size(), !preedit.text.empty()); std::string commit_text = base::UTF16ToUTF8(character_composer_.composed_character()); if (!commit_text.empty()) { @@ -587,11 +589,11 @@ bool InputMethodChromeOS::ExecuteCharacterComposer(const ui::KeyEvent& event) { } void InputMethodChromeOS::ExtractCompositionText( - const chromeos::CompositionText& text, - uint32 cursor_position, + const CompositionText& text, + uint32_t cursor_position, CompositionText* out_composition) const { out_composition->Clear(); - out_composition->text = text.text(); + out_composition->text = text.text; if (out_composition->text.empty()) return; @@ -606,7 +608,7 @@ void InputMethodChromeOS::ExtractCompositionText( } while (char_iterator.Advance()); // The text length in Unicode characters. - uint32 char_length = static_cast<uint32>(char16_offsets.size()); + uint32_t char_length = static_cast<uint32_t>(char16_offsets.size()); // Make sure we can convert the value of |char_length| as well. char16_offsets.push_back(length); @@ -615,36 +617,24 @@ void InputMethodChromeOS::ExtractCompositionText( out_composition->selection = gfx::Range(cursor_offset); - const std::vector<chromeos::CompositionText::UnderlineAttribute>& - underline_attributes = text.underline_attributes(); - if (!underline_attributes.empty()) { - for (size_t i = 0; i < underline_attributes.size(); ++i) { - const uint32 start = underline_attributes[i].start_index; - const uint32 end = underline_attributes[i].end_index; + const CompositionUnderlines text_underlines = text.underlines; + if (!text_underlines.empty()) { + for (size_t i = 0; i < text_underlines.size(); ++i) { + const uint32_t start = text_underlines[i].start_offset; + const uint32_t end = text_underlines[i].end_offset; if (start >= end) continue; - CompositionUnderline underline(char16_offsets[start], - char16_offsets[end], - SK_ColorBLACK, - false /* thick */, - SK_ColorTRANSPARENT); - if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE) - underline.thick = true; - else if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR) - underline.color = SK_ColorRED; - else if (underline_attributes[i].type == - chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_NONE) - underline.color = SK_ColorTRANSPARENT; + CompositionUnderline underline( + char16_offsets[start], char16_offsets[end], text_underlines[i].color, + text_underlines[i].thick, text_underlines[i].background_color); out_composition->underlines.push_back(underline); } } - DCHECK(text.selection_start() <= text.selection_end()); - if (text.selection_start() < text.selection_end()) { - const uint32 start = text.selection_start(); - const uint32 end = text.selection_end(); + DCHECK(text.selection.start() <= text.selection.end()); + if (text.selection.start() < text.selection.end()) { + const uint32_t start = text.selection.start(); + const uint32_t end = text.selection.end(); CompositionUnderline underline(char16_offsets[start], char16_offsets[end], SK_ColorBLACK, diff --git a/chromium/ui/base/ime/input_method_chromeos.h b/chromium/ui/base/ime/input_method_chromeos.h index d632bf4405a..28da9b7c9bb 100644 --- a/chromium/ui/base/ime/input_method_chromeos.h +++ b/chromium/ui/base/ime/input_method_chromeos.h @@ -5,16 +5,18 @@ #ifndef UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_ #define UI_BASE_IME_INPUT_METHOD_CHROMEOS_H_ +#include <stdint.h> + #include <set> #include <string> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "ui/base/ime/chromeos/character_composer.h" -#include "ui/base/ime/chromeos/ime_bridge.h" #include "ui/base/ime/composition_text.h" +#include "ui/base/ime/ime_input_context_handler_interface.h" #include "ui/base/ime/input_method_base.h" namespace ui { @@ -22,7 +24,7 @@ namespace ui { // A ui::InputMethod implementation based on IBus. class UI_BASE_IME_EXPORT InputMethodChromeOS : public InputMethodBase, - public chromeos::IMEInputContextHandlerInterface { + public ui::IMEInputContextHandlerInterface { public: explicit InputMethodChromeOS(internal::InputMethodDelegate* delegate); ~InputMethodChromeOS() override; @@ -42,8 +44,8 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS protected: // Converts |text| into CompositionText. - void ExtractCompositionText(const chromeos::CompositionText& text, - uint32 cursor_position, + void ExtractCompositionText(const CompositionText& text, + uint32_t cursor_position, CompositionText* out_composition) const; // Process a key returned from the input method. @@ -97,12 +99,12 @@ class UI_BASE_IME_EXPORT InputMethodChromeOS // true if character composer comsumes key event. bool ExecuteCharacterComposer(const ui::KeyEvent& event); - // chromeos::IMEInputContextHandlerInterface overrides: + // ui::IMEInputContextHandlerInterface overrides: void CommitText(const std::string& text) override; - void UpdateCompositionText(const chromeos::CompositionText& text, - uint32 cursor_pos, + void UpdateCompositionText(const CompositionText& text, + uint32_t cursor_pos, bool visible) override; - void DeleteSurroundingText(int32 offset, uint32 length) override; + void DeleteSurroundingText(int32_t offset, uint32_t length) override; // Hides the composition text. void HidePreeditText(); diff --git a/chromium/ui/base/ime/input_method_chromeos_unittest.cc b/chromium/ui/base/ime/input_method_chromeos_unittest.cc index c1dcdf21c2b..40677ea4db6 100644 --- a/chromium/ui/base/ime/input_method_chromeos_unittest.cc +++ b/chromium/ui/base/ime/input_method_chromeos_unittest.cc @@ -4,6 +4,8 @@ #include "ui/base/ime/input_method_chromeos.h" +#include <stddef.h> +#include <stdint.h> #include <X11/Xlib.h> #undef Bool #undef FocusIn @@ -13,14 +15,16 @@ #include <cstring> #include "base/i18n/char_iterator.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/ime/chromeos/composition_text_chromeos.h" -#include "ui/base/ime/chromeos/ime_bridge.h" #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h" #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" +#include "ui/base/ime/composition_text.h" #include "ui/base/ime/dummy_text_input_client.h" +#include "ui/base/ime/ime_bridge.h" +#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/text_input_client.h" #include "ui/events/event.h" @@ -39,11 +43,10 @@ namespace { const base::string16 kSampleText = base::UTF8ToUTF16( "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); -typedef chromeos::IMEEngineHandlerInterface::KeyEventDoneCallback - KeyEventCallback; +typedef IMEEngineHandlerInterface::KeyEventDoneCallback KeyEventCallback; -uint32 GetOffsetInUTF16( - const base::string16& utf16_string, uint32 utf8_offset) { +uint32_t GetOffsetInUTF16(const base::string16& utf16_string, + uint32_t utf8_offset) { DCHECK_LT(utf8_offset, utf16_string.size()); base::i18n::UTF16CharIterator char_iterator(&utf16_string); for (size_t i = 0; i < utf8_offset; ++i) @@ -104,9 +107,9 @@ class TestableInputMethodChromeOS : public InputMethodChromeOS { class SynchronousKeyEventHandler { public: - SynchronousKeyEventHandler(uint32 expected_keyval, - uint32 expected_keycode, - uint32 expected_state, + SynchronousKeyEventHandler(uint32_t expected_keyval, + uint32_t expected_keycode, + uint32_t expected_state, KeyEventHandlerBehavior behavior) : expected_keyval_(expected_keyval), expected_keycode_(expected_keycode), @@ -115,9 +118,9 @@ class SynchronousKeyEventHandler { virtual ~SynchronousKeyEventHandler() {} - void Run(uint32 keyval, - uint32 keycode, - uint32 state, + void Run(uint32_t keyval, + uint32_t keycode, + uint32_t state, const KeyEventCallback& callback) { EXPECT_EQ(expected_keyval_, keyval); EXPECT_EQ(expected_keycode_, keycode); @@ -126,9 +129,9 @@ class SynchronousKeyEventHandler { } private: - const uint32 expected_keyval_; - const uint32 expected_keycode_; - const uint32 expected_state_; + const uint32_t expected_keyval_; + const uint32_t expected_keycode_; + const uint32_t expected_state_; const KeyEventHandlerBehavior behavior_; DISALLOW_COPY_AND_ASSIGN(SynchronousKeyEventHandler); @@ -136,18 +139,18 @@ class SynchronousKeyEventHandler { class AsynchronousKeyEventHandler { public: - AsynchronousKeyEventHandler(uint32 expected_keyval, - uint32 expected_keycode, - uint32 expected_state) + AsynchronousKeyEventHandler(uint32_t expected_keyval, + uint32_t expected_keycode, + uint32_t expected_state) : expected_keyval_(expected_keyval), expected_keycode_(expected_keycode), expected_state_(expected_state) {} virtual ~AsynchronousKeyEventHandler() {} - void Run(uint32 keyval, - uint32 keycode, - uint32 state, + void Run(uint32_t keyval, + uint32_t keycode, + uint32_t state, const KeyEventCallback& callback) { EXPECT_EQ(expected_keyval_, keyval); EXPECT_EQ(expected_keycode_, keycode); @@ -160,9 +163,9 @@ class AsynchronousKeyEventHandler { } private: - const uint32 expected_keyval_; - const uint32 expected_keycode_; - const uint32 expected_state_; + const uint32_t expected_keyval_; + const uint32_t expected_keycode_; + const uint32_t expected_state_; KeyEventCallback callback_; DISALLOW_COPY_AND_ASSIGN(AsynchronousKeyEventHandler); @@ -171,15 +174,15 @@ class AsynchronousKeyEventHandler { class SetSurroundingTextVerifier { public: SetSurroundingTextVerifier(const std::string& expected_surrounding_text, - uint32 expected_cursor_position, - uint32 expected_anchor_position) + uint32_t expected_cursor_position, + uint32_t expected_anchor_position) : expected_surrounding_text_(expected_surrounding_text), expected_cursor_position_(expected_cursor_position), expected_anchor_position_(expected_anchor_position) {} void Verify(const std::string& text, - uint32 cursor_pos, - uint32 anchor_pos) { + uint32_t cursor_pos, + uint32_t anchor_pos) { EXPECT_EQ(expected_surrounding_text_, text); EXPECT_EQ(expected_cursor_position_, cursor_pos); EXPECT_EQ(expected_anchor_position_, anchor_pos); @@ -187,8 +190,8 @@ class SetSurroundingTextVerifier { private: const std::string expected_surrounding_text_; - const uint32 expected_cursor_position_; - const uint32 expected_anchor_position_; + const uint32_t expected_cursor_position_; + const uint32_t expected_anchor_position_; DISALLOW_COPY_AND_ASSIGN(SetSurroundingTextVerifier); }; @@ -206,16 +209,16 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, ~InputMethodChromeOSTest() override {} void SetUp() override { - chromeos::IMEBridge::Initialize(); + IMEBridge::Initialize(); mock_ime_engine_handler_.reset( new chromeos::MockIMEEngineHandler()); - chromeos::IMEBridge::Get()->SetCurrentEngineHandler( + IMEBridge::Get()->SetCurrentEngineHandler( mock_ime_engine_handler_.get()); mock_ime_candidate_window_handler_.reset( new chromeos::MockIMECandidateWindowHandler()); - chromeos::IMEBridge::Get()->SetCandidateWindowHandler( + IMEBridge::Get()->SetCandidateWindowHandler( mock_ime_candidate_window_handler_.get()); ime_.reset(new TestableInputMethodChromeOS(this)); @@ -226,11 +229,11 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, if (ime_.get()) ime_->SetFocusedTextInputClient(NULL); ime_.reset(); - chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); - chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); + IMEBridge::Get()->SetCurrentEngineHandler(NULL); + IMEBridge::Get()->SetCandidateWindowHandler(NULL); mock_ime_engine_handler_.reset(); mock_ime_candidate_window_handler_.reset(); - chromeos::IMEBridge::Shutdown(); + IMEBridge::Shutdown(); ResetFlags(); } @@ -256,9 +259,9 @@ class InputMethodChromeOSTest : public internal::InputMethodDelegate, void InsertText(const base::string16& text) override { inserted_text_ = text; } - void InsertChar(base::char16 ch, int flags) override { - inserted_char_ = ch; - inserted_char_flags_ = flags; + void InsertChar(const KeyEvent& event) override { + inserted_char_ = event.GetCharacter(); + inserted_char_flags_ = event.flags(); } TextInputType GetTextInputType() const override { return input_type_; } TextInputMode GetTextInputMode() const override { return input_mode_; } @@ -551,10 +554,10 @@ TEST_F(InputMethodChromeOSTest, OnCaretBoundsChanged) { TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_NoAttribute) { const base::string16 kSampleAsciiText = UTF8ToUTF16("Sample Text"); - const uint32 kCursorPos = 2UL; + const uint32_t kCursorPos = 2UL; - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleAsciiText); + CompositionText chromeos_composition_text; + chromeos_composition_text.text = kSampleAsciiText; CompositionText composition_text; ime_->ExtractCompositionText( @@ -572,192 +575,175 @@ TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_NoAttribute) { } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_SingleUnderline) { - const uint32 kCursorPos = 2UL; + const uint32_t kCursorPos = 2UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos::CompositionText::UnderlineAttribute underline; - underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_SINGLE; - underline.start_index = 1UL; - underline.end_index = 4UL; - chromeos_composition_text.mutable_underline_attributes()->push_back( - underline); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); + composition_text.text = kSampleText; + CompositionUnderline underline(1UL, 4UL, SK_ColorBLACK, false, + SK_ColorTRANSPARENT); + composition_text.underlines.push_back(underline); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); // If there is no selection, |selection| represents cursor position. - EXPECT_EQ(kCursorPos, composition_text.selection.start()); - EXPECT_EQ(kCursorPos, composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), - composition_text.underlines[0].end_offset); + EXPECT_EQ(kCursorPos, composition_text2.selection.start()); + EXPECT_EQ(kCursorPos, composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_offset), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_offset), + composition_text2.underlines[0].end_offset); // Single underline represents as black thin line. - EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); - EXPECT_FALSE(composition_text.underlines[0].thick); + EXPECT_EQ(SK_ColorBLACK, composition_text2.underlines[0].color); + EXPECT_FALSE(composition_text2.underlines[0].thick); EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), - composition_text.underlines[0].background_color); + composition_text2.underlines[0].background_color); } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_DoubleUnderline) { - const uint32 kCursorPos = 2UL; + const uint32_t kCursorPos = 2UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos::CompositionText::UnderlineAttribute underline; - underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_DOUBLE; - underline.start_index = 1UL; - underline.end_index = 4UL; - chromeos_composition_text.mutable_underline_attributes()->push_back( - underline); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); + composition_text.text = kSampleText; + CompositionUnderline underline(1UL, 4UL, SK_ColorBLACK, true, + SK_ColorTRANSPARENT); + composition_text.underlines.push_back(underline); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); // If there is no selection, |selection| represents cursor position. - EXPECT_EQ(kCursorPos, composition_text.selection.start()); - EXPECT_EQ(kCursorPos, composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), - composition_text.underlines[0].end_offset); + EXPECT_EQ(kCursorPos, composition_text2.selection.start()); + EXPECT_EQ(kCursorPos, composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_offset), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_offset), + composition_text2.underlines[0].end_offset); // Double underline represents as black thick line. - EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); - EXPECT_TRUE(composition_text.underlines[0].thick); + EXPECT_EQ(SK_ColorBLACK, composition_text2.underlines[0].color); + EXPECT_TRUE(composition_text2.underlines[0].thick); EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), - composition_text.underlines[0].background_color); + composition_text2.underlines[0].background_color); } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_ErrorUnderline) { - const uint32 kCursorPos = 2UL; + const uint32_t kCursorPos = 2UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos::CompositionText::UnderlineAttribute underline; - underline.type = chromeos::CompositionText::COMPOSITION_TEXT_UNDERLINE_ERROR; - underline.start_index = 1UL; - underline.end_index = 4UL; - chromeos_composition_text.mutable_underline_attributes()->push_back( - underline); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); - EXPECT_EQ(kCursorPos, composition_text.selection.start()); - EXPECT_EQ(kCursorPos, composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_index), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_index), - composition_text.underlines[0].end_offset); + composition_text.text = kSampleText; + CompositionUnderline underline(1UL, 4UL, SK_ColorRED, false, + SK_ColorTRANSPARENT); + composition_text.underlines.push_back(underline); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); + EXPECT_EQ(kCursorPos, composition_text2.selection.start()); + EXPECT_EQ(kCursorPos, composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.start_offset), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, underline.end_offset), + composition_text2.underlines[0].end_offset); // Error underline represents as red thin line. - EXPECT_EQ(SK_ColorRED, composition_text.underlines[0].color); - EXPECT_FALSE(composition_text.underlines[0].thick); + EXPECT_EQ(SK_ColorRED, composition_text2.underlines[0].color); + EXPECT_FALSE(composition_text2.underlines[0].thick); } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_Selection) { - const uint32 kCursorPos = 2UL; + const uint32_t kCursorPos = 2UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos_composition_text.set_selection_start(1UL); - chromeos_composition_text.set_selection_end(4UL); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); - EXPECT_EQ(kCursorPos, composition_text.selection.start()); - EXPECT_EQ(kCursorPos, composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_start()), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_end()), - composition_text.underlines[0].end_offset); - EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); - EXPECT_TRUE(composition_text.underlines[0].thick); + composition_text.text = kSampleText; + composition_text.selection.set_start(1UL); + composition_text.selection.set_end(4UL); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); + EXPECT_EQ(kCursorPos, composition_text2.selection.start()); + EXPECT_EQ(kCursorPos, composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.start()), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.end()), + composition_text2.underlines[0].end_offset); + EXPECT_EQ(SK_ColorBLACK, composition_text2.underlines[0].color); + EXPECT_TRUE(composition_text2.underlines[0].thick); EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), - composition_text.underlines[0].background_color); + composition_text2.underlines[0].background_color); } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_SelectionStartWithCursor) { - const uint32 kCursorPos = 1UL; + const uint32_t kCursorPos = 1UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos_composition_text.set_selection_start(kCursorPos); - chromeos_composition_text.set_selection_end(4UL); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); + composition_text.text = kSampleText; + composition_text.selection.set_start(kCursorPos); + composition_text.selection.set_end(4UL); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); // If the cursor position is same as selection bounds, selection start // position become opposit side of selection from cursor. - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_end()), - composition_text.selection.start()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.end()), + composition_text2.selection.start()); EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), - composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_start()), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_end()), - composition_text.underlines[0].end_offset); - EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); - EXPECT_TRUE(composition_text.underlines[0].thick); + composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.start()), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.end()), + composition_text2.underlines[0].end_offset); + EXPECT_EQ(SK_ColorBLACK, composition_text2.underlines[0].color); + EXPECT_TRUE(composition_text2.underlines[0].thick); EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), - composition_text.underlines[0].background_color); + composition_text2.underlines[0].background_color); } TEST_F(InputMethodChromeOSTest, ExtractCompositionTextTest_SelectionEndWithCursor) { - const uint32 kCursorPos = 4UL; + const uint32_t kCursorPos = 4UL; // Set up chromeos composition text with one underline attribute. - chromeos::CompositionText chromeos_composition_text; - chromeos_composition_text.set_text(kSampleText); - chromeos_composition_text.set_selection_start(1UL); - chromeos_composition_text.set_selection_end(kCursorPos); - CompositionText composition_text; - ime_->ExtractCompositionText( - chromeos_composition_text, kCursorPos, &composition_text); - EXPECT_EQ(kSampleText, composition_text.text); + composition_text.text = kSampleText; + composition_text.selection.set_start(1UL); + composition_text.selection.set_end(kCursorPos); + + CompositionText composition_text2; + ime_->ExtractCompositionText(composition_text, kCursorPos, + &composition_text2); + EXPECT_EQ(kSampleText, composition_text2.text); // If the cursor position is same as selection bounds, selection start // position become opposit side of selection from cursor. - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_start()), - composition_text.selection.start()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.start()), + composition_text2.selection.start()); EXPECT_EQ(GetOffsetInUTF16(kSampleText, kCursorPos), - composition_text.selection.end()); - ASSERT_EQ(1UL, composition_text.underlines.size()); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_start()), - composition_text.underlines[0].start_offset); - EXPECT_EQ(GetOffsetInUTF16(kSampleText, - chromeos_composition_text.selection_end()), - composition_text.underlines[0].end_offset); - EXPECT_EQ(SK_ColorBLACK, composition_text.underlines[0].color); - EXPECT_TRUE(composition_text.underlines[0].thick); + composition_text2.selection.end()); + ASSERT_EQ(1UL, composition_text2.underlines.size()); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.start()), + composition_text2.underlines[0].start_offset); + EXPECT_EQ(GetOffsetInUTF16(kSampleText, composition_text.selection.end()), + composition_text2.underlines[0].end_offset); + EXPECT_EQ(SK_ColorBLACK, composition_text2.underlines[0].color); + EXPECT_TRUE(composition_text2.underlines[0].thick); EXPECT_EQ(static_cast<SkColor>(SK_ColorTRANSPARENT), - composition_text.underlines[0].background_color); + composition_text2.underlines[0].background_color); } TEST_F(InputMethodChromeOSTest, SurroundingText_NoSelectionTest) { @@ -896,7 +882,7 @@ TEST_F(InputMethodChromeOSKeyEventTest, KeyEventDelayResponseTest) { EXPECT_EQ(kFlags, key_event->flags()); EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); - (static_cast<chromeos::IMEInputContextHandlerInterface*>(ime_.get())) + (static_cast<IMEInputContextHandlerInterface*>(ime_.get())) ->CommitText("A"); EXPECT_EQ(0, inserted_char_); @@ -947,17 +933,17 @@ TEST_F(InputMethodChromeOSKeyEventTest, MultiKeyEventDelayResponseTest) { mock_ime_engine_handler_->process_key_event_call_count()); EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); - chromeos::CompositionText comp; - comp.set_text(base::ASCIIToUTF16("B")); - (static_cast<chromeos::IMEInputContextHandlerInterface*>(ime_.get())) - ->UpdateCompositionText(comp, comp.text().length(), true); + CompositionText comp; + comp.text = base::ASCIIToUTF16("B"); + (static_cast<IMEInputContextHandlerInterface*>(ime_.get())) + ->UpdateCompositionText(comp, comp.text.length(), true); EXPECT_EQ(0, composition_text_.text[0]); // Do callback for first key event. first_callback.Run(true); - EXPECT_EQ(comp.text(), composition_text_.text); + EXPECT_EQ(comp.text, composition_text_.text); // Check the results for first key event. EXPECT_EQ(1, ime_->process_key_event_post_ime_call_count()); diff --git a/chromium/ui/base/ime/input_method_factory.cc b/chromium/ui/base/ime/input_method_factory.cc index b4aa3cd9e4a..dd9d31a6665 100644 --- a/chromium/ui/base/ime/input_method_factory.cc +++ b/chromium/ui/base/ime/input_method_factory.cc @@ -4,12 +4,12 @@ #include "ui/base/ime/input_method_factory.h" +#include "build/build_config.h" #include "ui/base/ime/mock_input_method.h" #if defined(OS_CHROMEOS) #include "ui/base/ime/input_method_chromeos.h" #elif defined(OS_WIN) -#include "base/win/metro.h" #include "ui/base/ime/input_method_win.h" #include "ui/base/ime/remote_input_method_win.h" #elif defined(OS_MACOSX) @@ -17,6 +17,8 @@ #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ !defined(OS_CHROMEOS) #include "ui/base/ime/input_method_auralinux.h" +#elif defined(OS_ANDROID) +#include "ui/base/ime/input_method_android.h" #else #include "ui/base/ime/input_method_minimal.h" #endif @@ -59,6 +61,8 @@ scoped_ptr<InputMethod> CreateInputMethod( #elif defined(USE_AURA) && defined(OS_LINUX) && defined(USE_X11) && \ !defined(OS_CHROMEOS) return make_scoped_ptr(new InputMethodAuraLinux(delegate)); +#elif defined(OS_ANDROID) + return make_scoped_ptr(new InputMethodAndroid(delegate)); #else return make_scoped_ptr(new InputMethodMinimal(delegate)); #endif diff --git a/chromium/ui/base/ime/input_method_factory.h b/chromium/ui/base/ime/input_method_factory.h index 30132cb66f6..3de9c5c3944 100644 --- a/chromium/ui/base/ime/input_method_factory.h +++ b/chromium/ui/base/ime/input_method_factory.h @@ -5,7 +5,6 @@ #ifndef UI_BASE_IME_INPUT_METHOD_FACTORY_H_ #define UI_BASE_IME_INPUT_METHOD_FACTORY_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "ui/base/ime/input_method_initializer.h" diff --git a/chromium/ui/base/ime/input_method_initializer.cc b/chromium/ui/base/ime/input_method_initializer.cc index 2fca46cff47..1ac3c27aa46 100644 --- a/chromium/ui/base/ime/input_method_initializer.cc +++ b/chromium/ui/base/ime/input_method_initializer.cc @@ -4,8 +4,10 @@ #include "ui/base/ime/input_method_initializer.h" +#include "build/build_config.h" + #if defined(OS_CHROMEOS) -#include "ui/base/ime/chromeos/ime_bridge.h" +#include "ui/base/ime/ime_bridge.h" #elif defined(USE_AURA) && defined(OS_LINUX) #include "base/logging.h" #include "ui/base/ime/linux/fake_input_method_context_factory.h" @@ -23,19 +25,19 @@ namespace ui { void InitializeInputMethod() { #if defined(OS_CHROMEOS) - chromeos::IMEBridge::Initialize(); + IMEBridge::Initialize(); #endif } void ShutdownInputMethod() { #if defined(OS_CHROMEOS) - chromeos::IMEBridge::Shutdown(); + IMEBridge::Shutdown(); #endif } void InitializeInputMethodForTesting() { #if defined(OS_CHROMEOS) - chromeos::IMEBridge::Initialize(); + IMEBridge::Initialize(); #elif defined(USE_AURA) && defined(OS_LINUX) if (!g_linux_input_method_context_factory) g_linux_input_method_context_factory = new FakeInputMethodContextFactory(); @@ -51,7 +53,7 @@ void InitializeInputMethodForTesting() { void ShutdownInputMethodForTesting() { #if defined(OS_CHROMEOS) - chromeos::IMEBridge::Shutdown(); + IMEBridge::Shutdown(); #elif defined(USE_AURA) && defined(OS_LINUX) const LinuxInputMethodContextFactory* factory = LinuxInputMethodContextFactory::instance(); diff --git a/chromium/ui/base/ime/input_method_initializer.h b/chromium/ui/base/ime/input_method_initializer.h index 787d7cce3e9..588d7f1c4aa 100644 --- a/chromium/ui/base/ime/input_method_initializer.h +++ b/chromium/ui/base/ime/input_method_initializer.h @@ -5,7 +5,6 @@ #ifndef UI_BASE_IME_INPUT_METHOD_INITIALIZER_H_ #define UI_BASE_IME_INPUT_METHOD_INITIALIZER_H_ -#include "base/basictypes.h" #include "ui/base/ime/ui_base_ime_export.h" namespace ui { diff --git a/chromium/ui/base/ime/input_method_mac.h b/chromium/ui/base/ime/input_method_mac.h index e14925c3e8c..a792400796b 100644 --- a/chromium/ui/base/ime/input_method_mac.h +++ b/chromium/ui/base/ime/input_method_mac.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_INPUT_METHOD_MAC_H_ #define UI_BASE_IME_INPUT_METHOD_MAC_H_ +#include "base/macros.h" #include "ui/base/ime/input_method_base.h" namespace ui { diff --git a/chromium/ui/base/ime/input_method_minimal.cc b/chromium/ui/base/ime/input_method_minimal.cc index cd00702111f..8a5670e40a3 100644 --- a/chromium/ui/base/ime/input_method_minimal.cc +++ b/chromium/ui/base/ime/input_method_minimal.cc @@ -4,6 +4,8 @@ #include "ui/base/ime/input_method_minimal.h" +#include <stdint.h> + #include "ui/base/ime/text_input_client.h" #include "ui/events/event.h" #include "ui/events/event_constants.h" @@ -35,9 +37,9 @@ void InputMethodMinimal::DispatchKeyEvent(ui::KeyEvent* event) { // Insert the character. ignore_result(DispatchKeyEventPostIME(event)); if (event->type() == ET_KEY_PRESSED && GetTextInputClient()) { - const uint16 ch = event->GetCharacter(); + const uint16_t ch = event->GetCharacter(); if (ch) { - GetTextInputClient()->InsertChar(ch, event->flags()); + GetTextInputClient()->InsertChar(*event); event->StopPropagation(); } } diff --git a/chromium/ui/base/ime/input_method_minimal.h b/chromium/ui/base/ime/input_method_minimal.h index 60d1a8e23f9..cab74ad33f6 100644 --- a/chromium/ui/base/ime/input_method_minimal.h +++ b/chromium/ui/base/ime/input_method_minimal.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_INPUT_METHOD_MINIMAL_H_ #define UI_BASE_IME_INPUT_METHOD_MINIMAL_H_ +#include "base/macros.h" #include "ui/base/ime/input_method_base.h" namespace ui { diff --git a/chromium/ui/base/ime/input_method_win.cc b/chromium/ui/base/ime/input_method_win.cc index df75bb2ff90..56bbac1b324 100644 --- a/chromium/ui/base/ime/input_method_win.cc +++ b/chromium/ui/base/ime/input_method_win.cc @@ -4,10 +4,14 @@ #include "ui/base/ime/input_method_win.h" +#include <stddef.h> +#include <stdint.h> + #include "base/auto_reset.h" -#include "base/basictypes.h" +#include "base/command_line.h" #include "ui/base/ime/text_input_client.h" #include "ui/base/ime/win/tsf_input_scope.h" +#include "ui/base/ui_base_switches.h" #include "ui/events/event.h" #include "ui/events/event_constants.h" #include "ui/events/event_utils.h" @@ -31,8 +35,7 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, accept_carriage_return_(false), enabled_(false), is_candidate_popup_open_(false), - composing_window_handle_(NULL), - suppress_next_char_(false) { + composing_window_handle_(NULL) { SetDelegate(delegate); } @@ -81,8 +84,8 @@ bool InputMethodWin::OnUntranslatedIMEMessage( break; case WM_CHAR: case WM_SYSCHAR: - original_result = OnChar( - event.hwnd, event.message, event.wParam, event.lParam, &handled); + original_result = OnChar(event.hwnd, event.message, event.wParam, + event.lParam, event, &handled); break; case WM_IME_NOTIFY: original_result = OnImeNotify( @@ -104,14 +107,42 @@ void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { } const base::NativeEvent& native_key_event = event->native_event(); + BOOL handled = FALSE; if (native_key_event.message == WM_CHAR) { - BOOL handled; OnChar(native_key_event.hwnd, native_key_event.message, - native_key_event.wParam, native_key_event.lParam, &handled); + native_key_event.wParam, native_key_event.lParam, native_key_event, + &handled); if (handled) event->StopPropagation(); return; } + + std::vector<MSG> char_msgs; + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableMergeKeyCharEvents)) { + // Combines the WM_KEY* and WM_CHAR messages in the event processing flow + // which is necessary to let Chrome IME extension to process the key event + // and perform corresponding IME actions. + // Chrome IME extension may wants to consume certain key events based on + // the character information of WM_CHAR messages. Holding WM_KEY* messages + // until WM_CHAR is processed by the IME extension is not feasible because + // there is no way to know wether there will or not be a WM_CHAR following + // the WM_KEY*. + // Chrome never handles dead chars so it is safe to remove/ignore + // WM_*DEADCHAR messages. + MSG msg; + while (::PeekMessage(&msg, native_key_event.hwnd, WM_CHAR, WM_DEADCHAR, + PM_REMOVE)) { + if (msg.message == WM_CHAR) + char_msgs.push_back(msg); + } + while (::PeekMessage(&msg, native_key_event.hwnd, WM_SYSCHAR, + WM_SYSDEADCHAR, PM_REMOVE)) { + if (msg.message == WM_SYSCHAR) + char_msgs.push_back(msg); + } + } + // Handles ctrl-shift key to change text direction and layout alignment. if (ui::IMM32Manager::IsRTLKeyboardLayoutInstalled() && !IsTextInputTypeNone()) { @@ -135,9 +166,20 @@ void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { } } + // If only 1 WM_CHAR per the key event, set it as the character of it. + if (char_msgs.size() == 1) + event->set_character(static_cast<base::char16>(char_msgs[0].wParam)); + ui::EventDispatchDetails details = DispatchKeyEventPostIME(event); - if (!details.dispatcher_destroyed) - suppress_next_char_ = event->stopped_propagation(); + if (details.dispatcher_destroyed || details.target_destroyed || + event->stopped_propagation()) { + return; + } + + for (size_t i = 0; i < char_msgs.size(); ++i) { + MSG msg = char_msgs[i]; + OnChar(msg.hwnd, msg.message, msg.wParam, msg.lParam, msg, &handled); + } } void InputMethodWin::OnTextInputTypeChanged(const TextInputClient* client) { @@ -216,14 +258,10 @@ LRESULT InputMethodWin::OnChar(HWND window_handle, UINT message, WPARAM wparam, LPARAM lparam, + const base::NativeEvent& event, BOOL* handled) { *handled = TRUE; - if (suppress_next_char_) { - suppress_next_char_ = false; - return 0; - } - // We need to send character events to the focused text input client event if // its text input type is ui::TEXT_INPUT_TYPE_NONE. if (GetTextInputClient()) { @@ -232,13 +270,15 @@ LRESULT InputMethodWin::OnChar(HWND window_handle, // A mask to determine the previous key state from |lparam|. The value is 1 // if the key is down before the message is sent, or it is 0 if the key is // up. - const uint32 kPrevKeyDownBit = 0x40000000; + const uint32_t kPrevKeyDownBit = 0x40000000; if (ch == kCarriageReturn && !(lparam & kPrevKeyDownBit)) accept_carriage_return_ = true; // Conditionally ignore '\r' events to work around crbug.com/319100. // TODO(yukawa, IME): Figure out long-term solution. - if (ch != kCarriageReturn || accept_carriage_return_) - GetTextInputClient()->InsertChar(ch, ui::GetModifiersFromKeyState()); + if (ch != kCarriageReturn || accept_carriage_return_) { + ui::KeyEvent char_event(event); + GetTextInputClient()->InsertChar(char_event); + } } // Explicitly show the system menu at a good location on [Alt]+[Space]. @@ -554,14 +594,10 @@ bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { void InputMethodWin::DispatchFabricatedKeyEvent(ui::KeyEvent* event) { if (event->is_char()) { - if (suppress_next_char_) { - suppress_next_char_ = false; - return; - } if (GetTextInputClient()) { - GetTextInputClient()->InsertChar( - static_cast<base::char16>(event->key_code()), - ui::GetModifiersFromKeyState()); + ui::KeyEvent ch_event(*event); + ch_event.set_character(static_cast<base::char16>(event->key_code())); + GetTextInputClient()->InsertChar(ch_event); return; } } diff --git a/chromium/ui/base/ime/input_method_win.h b/chromium/ui/base/ime/input_method_win.h index 4814f269c2f..ce411491e23 100644 --- a/chromium/ui/base/ime/input_method_win.h +++ b/chromium/ui/base/ime/input_method_win.h @@ -9,8 +9,8 @@ #include <string> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/ime/input_method_base.h" #include "ui/base/ime/win/imm32_manager.h" @@ -50,6 +50,7 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { UINT message, WPARAM wparam, LPARAM lparam, + const base::NativeEvent& event, BOOL* handled); LRESULT OnImeSetContext(HWND window_handle, @@ -129,10 +130,6 @@ class UI_BASE_IME_EXPORT InputMethodWin : public InputMethodBase { // composition. HWND composing_window_handle_; - // Set to true to suppress the next WM_CHAR, when the WM_KEYDOWN gets stopped - // propagation (e.g. triggered an accelerator). - bool suppress_next_char_; - DISALLOW_COPY_AND_ASSIGN(InputMethodWin); }; diff --git a/chromium/ui/base/ime/linux/fake_input_method_context.h b/chromium/ui/base/ime/linux/fake_input_method_context.h index 717a0192f77..ec9ac7e445a 100644 --- a/chromium/ui/base/ime/linux/fake_input_method_context.h +++ b/chromium/ui/base/ime/linux/fake_input_method_context.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_LINUX_FAKE_INPUT_METHOD_CONTEXT_H_ #define UI_BASE_IME_LINUX_FAKE_INPUT_METHOD_CONTEXT_H_ +#include "base/macros.h" #include "ui/base/ime/linux/linux_input_method_context.h" namespace ui { diff --git a/chromium/ui/base/ime/linux/fake_input_method_context_factory.h b/chromium/ui/base/ime/linux/fake_input_method_context_factory.h index a385f320eb2..591e0d4c784 100644 --- a/chromium/ui/base/ime/linux/fake_input_method_context_factory.h +++ b/chromium/ui/base/ime/linux/fake_input_method_context_factory.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_IME_LINUX_FAKE_INPUT_METHOD_CONTEXT_FACTORY_H_ #define UI_BASE_IME_LINUX_FAKE_INPUT_METHOD_CONTEXT_FACTORY_H_ +#include "base/macros.h" #include "ui/base/ime/linux/linux_input_method_context_factory.h" namespace ui { diff --git a/chromium/ui/base/ime/mock_input_method.h b/chromium/ui/base/ime/mock_input_method.h index 0925e4632ff..96d2c47f344 100644 --- a/chromium/ui/base/ime/mock_input_method.h +++ b/chromium/ui/base/ime/mock_input_method.h @@ -7,8 +7,8 @@ #include <string> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/observer_list.h" #include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method_observer.h" diff --git a/chromium/ui/base/ime/remote_input_method_delegate_win.h b/chromium/ui/base/ime/remote_input_method_delegate_win.h index b65d8c354c2..a172c7b5100 100644 --- a/chromium/ui/base/ime/remote_input_method_delegate_win.h +++ b/chromium/ui/base/ime/remote_input_method_delegate_win.h @@ -5,9 +5,10 @@ #ifndef UI_BASE_IME_REMOTE_INPUT_METHOD_DELEGATE_WIN_H_ #define UI_BASE_IME_REMOTE_INPUT_METHOD_DELEGATE_WIN_H_ +#include <stdint.h> + #include <vector> -#include "base/basictypes.h" #include "ui/base/ime/ui_base_ime_export.h" #include "ui/gfx/geometry/rect.h" @@ -26,12 +27,12 @@ class UI_BASE_IME_EXPORT RemoteInputMethodDelegateWin { // Notifies that properties of the focused TextInputClient is changed. // Note that an empty |input_scopes| represents that TextInputType is // TEXT_INPUT_TYPE_NONE. - // Caveats: |input_scopes| is defined as std::vector<int32> rather than + // Caveats: |input_scopes| is defined as std::vector<int32_t> rather than // std::vector<InputScope> because the wire format of IPC message - // MetroViewerHostMsg_ImeTextInputClientUpdated uses std::vector<int32> to + // MetroViewerHostMsg_ImeTextInputClientUpdated uses std::vector<int32_t> to // avoid dependency on <InputScope.h> header. virtual void OnTextInputClientUpdated( - const std::vector<int32>& input_scopes, + const std::vector<int32_t>& input_scopes, const std::vector<gfx::Rect>& composition_character_bounds) = 0; }; diff --git a/chromium/ui/base/ime/remote_input_method_win.cc b/chromium/ui/base/ime/remote_input_method_win.cc index 1a589bb0668..27d242a384b 100644 --- a/chromium/ui/base/ime/remote_input_method_win.cc +++ b/chromium/ui/base/ime/remote_input_method_win.cc @@ -4,10 +4,13 @@ #include "ui/base/ime/remote_input_method_win.h" +#include <stddef.h> +#include <stdint.h> + #include "base/command_line.h" +#include "base/macros.h" #include "base/observer_list.h" #include "base/strings/utf_string_conversions.h" -#include "base/win/metro.h" #include "base/win/scoped_handle.h" #include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method_delegate.h" @@ -60,16 +63,16 @@ std::string GetLocaleString(LCID Locale_id, LCTYPE locale_type) { //|chars_written| includes NUL terminator. const int chars_written = GetLocaleInfo(Locale_id, locale_type, buffer, arraysize(buffer)); - if (chars_written <= 1 || arraysize(buffer) < chars_written) + if (chars_written <= 1 || static_cast<int>(arraysize(buffer)) < chars_written) return std::string(); std::string result; base::WideToUTF8(buffer, chars_written - 1, &result); return result; } -std::vector<int32> GetInputScopesAsInt(TextInputType text_input_type, - TextInputMode text_input_mode) { - std::vector<int32> result; +std::vector<int32_t> GetInputScopesAsInt(TextInputType text_input_type, + TextInputMode text_input_mode) { + std::vector<int32_t> result; // An empty vector represents |text_input_type| is TEXT_INPUT_TYPE_NONE. if (text_input_type == TEXT_INPUT_TYPE_NONE) return result; @@ -78,7 +81,7 @@ std::vector<int32> GetInputScopesAsInt(TextInputType text_input_type, tsf_inputscope::GetInputScopes(text_input_type, text_input_mode); result.reserve(input_scopes.size()); for (size_t i = 0; i < input_scopes.size(); ++i) - result.push_back(static_cast<int32>(input_scopes[i])); + result.push_back(static_cast<int32_t>(input_scopes[i])); return result; } @@ -91,7 +94,7 @@ std::vector<gfx::Rect> GetCompositionCharacterBounds( if (client->HasCompositionText()) { gfx::Range range; if (client->GetCompositionTextRange(&range)) { - for (uint32 i = 0; i < range.length(); ++i) { + for (uint32_t i = 0; i < range.length(); ++i) { gfx::Rect rect; if (!client->GetCompositionCharacterBounds(i, &rect)) break; @@ -144,7 +147,7 @@ class RemoteInputMethodWin : public InputMethod, } void SetFocusedTextInputClient(TextInputClient* client) override { - std::vector<int32> prev_input_scopes; + std::vector<int32_t> prev_input_scopes; std::swap(input_scopes_, prev_input_scopes); std::vector<gfx::Rect> prev_bounds; std::swap(composition_character_bounds_, prev_bounds); @@ -183,9 +186,7 @@ class RemoteInputMethodWin : public InputMethod, if (event->HasNativeEvent()) { const base::NativeEvent& native_key_event = event->native_event(); if (native_key_event.message == WM_CHAR && text_input_client_) { - text_input_client_->InsertChar( - static_cast<base::char16>(native_key_event.wParam), - ui::GetModifiersFromKeyState()); + text_input_client_->InsertChar(*event); event->StopPropagation(); } return; @@ -193,9 +194,7 @@ class RemoteInputMethodWin : public InputMethod, if (event->is_char()) { if (text_input_client_) { - text_input_client_->InsertChar( - event->GetCharacter(), - ui::GetModifiersFromKeyState()); + text_input_client_->InsertChar(*event); } event->StopPropagation(); return; @@ -207,7 +206,7 @@ class RemoteInputMethodWin : public InputMethod, void OnTextInputTypeChanged(const TextInputClient* client) override { if (!text_input_client_ || text_input_client_ != client) return; - std::vector<int32> prev_input_scopes; + std::vector<int32_t> prev_input_scopes; std::swap(input_scopes_, prev_input_scopes); input_scopes_ = GetInputScopesAsInt(client->GetTextInputType(), client->GetTextInputMode()); @@ -319,8 +318,12 @@ class RemoteInputMethodWin : public InputMethod, // According to the comment in text_input_client.h, // TextInputClient::InsertText should never be called when the // text input type is TEXT_INPUT_TYPE_NONE. - for (size_t i = 0; i < text.size(); ++i) - text_input_client_->InsertChar(text[i], 0); + + for (size_t i = 0; i < text.size(); ++i) { + ui::KeyEvent char_event(text[i], static_cast<ui::KeyboardCode>(text[i]), + ui::EF_NONE); + text_input_client_->InsertChar(char_event); + } return; } text_input_client_->InsertText(text); @@ -339,7 +342,7 @@ class RemoteInputMethodWin : public InputMethod, internal::RemoteInputMethodDelegateWin* remote_delegate_; TextInputClient* text_input_client_; - std::vector<int32> input_scopes_; + std::vector<int32_t> input_scopes_; std::vector<gfx::Rect> composition_character_bounds_; bool is_candidate_popup_open_; bool is_ime_; @@ -362,9 +365,8 @@ bool IsRemoteInputMethodWinRequired(gfx::AcceleratedWidget widget) { PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id)); if (!process_handle.IsValid()) return false; - return base::win::IsProcessImmersive(process_handle.Get()) || - base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kViewerConnect); + return base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kViewerConnect); } RemoteInputMethodPrivateWin::RemoteInputMethodPrivateWin() {} diff --git a/chromium/ui/base/ime/remote_input_method_win.h b/chromium/ui/base/ime/remote_input_method_win.h index 3f822cfe494..a1725b32dd3 100644 --- a/chromium/ui/base/ime/remote_input_method_win.h +++ b/chromium/ui/base/ime/remote_input_method_win.h @@ -9,8 +9,8 @@ #include <string> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "ui/base/ime/ui_base_ime_export.h" diff --git a/chromium/ui/base/ime/remote_input_method_win_unittest.cc b/chromium/ui/base/ime/remote_input_method_win_unittest.cc index 686937b2eca..2d15919d938 100644 --- a/chromium/ui/base/ime/remote_input_method_win_unittest.cc +++ b/chromium/ui/base/ime/remote_input_method_win_unittest.cc @@ -5,9 +5,12 @@ #include "ui/base/ime/remote_input_method_win.h" #include <InputScope.h> +#include <stddef.h> +#include <stdint.h> #include <vector> +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/scoped_observer.h" #include "base/strings/string16.h" @@ -79,8 +82,8 @@ class MockTextInputClient : public DummyTextInputClient { void SetCompositionText(const ui::CompositionText& composition) override { ++call_count_set_composition_text_; } - void InsertChar(base::char16 ch, int flags) override { - inserted_text_.append(1, ch); + void InsertChar(const ui::KeyEvent& event) override { + inserted_text_.append(1, event.GetCharacter()); ++call_count_insert_char_; } void InsertText(const base::string16& text) override { @@ -94,7 +97,7 @@ class MockTextInputClient : public DummyTextInputClient { return text_input_mode_; } gfx::Rect GetCaretBounds() const override { return caret_bounds_; } - bool GetCompositionCharacterBounds(uint32 index, + bool GetCompositionCharacterBounds(uint32_t index, gfx::Rect* rect) const override { // Emulate the situation of crbug.com/328237. if (emulate_pepper_flash_) @@ -164,9 +167,7 @@ class MockRemoteInputMethodDelegateWin bool text_input_client_updated_called() const { return text_input_client_updated_called_; } - const std::vector<int32>& input_scopes() const { - return input_scopes_; - } + const std::vector<int32_t>& input_scopes() const { return input_scopes_; } const std::vector<gfx::Rect>& composition_character_bounds() const { return composition_character_bounds_; } @@ -181,7 +182,7 @@ class MockRemoteInputMethodDelegateWin void CancelComposition() override { cancel_composition_called_ = true; } void OnTextInputClientUpdated( - const std::vector<int32>& input_scopes, + const std::vector<int32_t>& input_scopes, const std::vector<gfx::Rect>& composition_character_bounds) override { text_input_client_updated_called_ = true; input_scopes_ = input_scopes; @@ -190,7 +191,7 @@ class MockRemoteInputMethodDelegateWin bool cancel_composition_called_; bool text_input_client_updated_called_; - std::vector<int32> input_scopes_; + std::vector<int32_t> input_scopes_; std::vector<gfx::Rect> composition_character_bounds_; DISALLOW_COPY_AND_ASSIGN(MockRemoteInputMethodDelegateWin); }; @@ -335,10 +336,10 @@ TEST(RemoteInputMethodWinTest, SetFocusedTextInputClient) { // Initial state must be synced. EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); - ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); + ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); EXPECT_EQ(gfx::Rect(10, 0, 10, 20), mock_remote_delegate.composition_character_bounds()[0]); - ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); + ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); // State must be cleared by SetFocusedTextInputClient(NULL). @@ -366,10 +367,10 @@ TEST(RemoteInputMethodWinTest, DetachTextInputClient) { // Initial state must be synced. EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); - ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); + ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); EXPECT_EQ(gfx::Rect(10, 0, 10, 20), mock_remote_delegate.composition_character_bounds()[0]); - ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); + ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); // State must be cleared by DetachTextInputClient @@ -399,7 +400,7 @@ TEST(RemoteInputMethodWinTest, OnCaretBoundsChanged) { // Initial state must be synced. EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); - ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); + ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); EXPECT_EQ(gfx::Rect(10, 0, 10, 20), mock_remote_delegate.composition_character_bounds()[0]); @@ -414,7 +415,7 @@ TEST(RemoteInputMethodWinTest, OnCaretBoundsChanged) { mock_text_input_client.set_caret_bounds(gfx::Rect(10, 20, 30, 40)); input_method->OnCaretBoundsChanged(&mock_text_input_client); EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); - ASSERT_EQ(1, mock_remote_delegate.composition_character_bounds().size()); + ASSERT_EQ(1u, mock_remote_delegate.composition_character_bounds().size()); EXPECT_EQ(gfx::Rect(10, 20, 30, 40), mock_remote_delegate.composition_character_bounds()[0]); @@ -484,7 +485,7 @@ TEST(RemoteInputMethodWinTest, OnTextInputTypeChanged) { // Initial state must be synced. EXPECT_TRUE(mock_remote_delegate.text_input_client_updated_called()); - ASSERT_EQ(1, mock_remote_delegate.input_scopes().size()); + ASSERT_EQ(1u, mock_remote_delegate.input_scopes().size()); EXPECT_EQ(IS_URL, mock_remote_delegate.input_scopes()[0]); // Check TEXT_INPUT_TYPE_NONE is handled. @@ -616,7 +617,7 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { input_method->DispatchKeyEvent(&fabricated_keydown); EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); - ASSERT_EQ(1, delegate_.fabricated_key_events().size()); + ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); delegate_.Reset(); mock_text_input_client.Reset(); @@ -632,7 +633,7 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { input_method->DispatchKeyEvent(&fabricated_keydown); EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); - ASSERT_EQ(1, delegate_.fabricated_key_events().size()); + ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); delegate_.Reset(); mock_text_input_client.Reset(); @@ -643,7 +644,7 @@ TEST(RemoteInputMethodWinTest, DispatchKeyEvent_FabricatedKeyDown) { input_method->DispatchKeyEvent(&fabricated_keydown); EXPECT_TRUE(fabricated_keydown.handled()); EXPECT_TRUE(mock_text_input_client.inserted_text().empty()); - ASSERT_EQ(1, delegate_.fabricated_key_events().size()); + ASSERT_EQ(1u, delegate_.fabricated_key_events().size()); EXPECT_EQ(L'A', delegate_.fabricated_key_events()[0]); delegate_.Reset(); mock_text_input_client.Reset(); @@ -718,7 +719,7 @@ TEST(RemoteInputMethodWinTest, OnCompositionChanged) { // TextInputClient is not focused yet here. private_ptr->OnCompositionChanged(composition_text); - EXPECT_EQ(0, mock_text_input_client.call_count_set_composition_text()); + EXPECT_EQ(0u, mock_text_input_client.call_count_set_composition_text()); delegate_.Reset(); mock_text_input_client.Reset(); @@ -727,7 +728,7 @@ TEST(RemoteInputMethodWinTest, OnCompositionChanged) { // TextInputClient is now focused here. private_ptr->OnCompositionChanged(composition_text); - EXPECT_EQ(1, mock_text_input_client.call_count_set_composition_text()); + EXPECT_EQ(1u, mock_text_input_client.call_count_set_composition_text()); delegate_.Reset(); mock_text_input_client.Reset(); } @@ -749,8 +750,8 @@ TEST(RemoteInputMethodWinTest, OnTextCommitted) { mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); private_ptr->OnTextCommitted(committed_text); - EXPECT_EQ(0, mock_text_input_client.call_count_insert_char()); - EXPECT_EQ(0, mock_text_input_client.call_count_insert_text()); + EXPECT_EQ(0u, mock_text_input_client.call_count_insert_char()); + EXPECT_EQ(0u, mock_text_input_client.call_count_insert_text()); EXPECT_EQ(L"", mock_text_input_client.inserted_text()); delegate_.Reset(); mock_text_input_client.Reset(); @@ -761,8 +762,8 @@ TEST(RemoteInputMethodWinTest, OnTextCommitted) { mock_text_input_client.set_text_input_type(TEXT_INPUT_TYPE_TEXT); private_ptr->OnTextCommitted(committed_text); - EXPECT_EQ(0, mock_text_input_client.call_count_insert_char()); - EXPECT_EQ(1, mock_text_input_client.call_count_insert_text()); + EXPECT_EQ(0u, mock_text_input_client.call_count_insert_char()); + EXPECT_EQ(1u, mock_text_input_client.call_count_insert_text()); EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); delegate_.Reset(); mock_text_input_client.Reset(); @@ -773,7 +774,7 @@ TEST(RemoteInputMethodWinTest, OnTextCommitted) { private_ptr->OnTextCommitted(committed_text); EXPECT_EQ(committed_text.size(), mock_text_input_client.call_count_insert_char()); - EXPECT_EQ(0, mock_text_input_client.call_count_insert_text()); + EXPECT_EQ(0u, mock_text_input_client.call_count_insert_text()); EXPECT_EQ(committed_text, mock_text_input_client.inserted_text()); delegate_.Reset(); mock_text_input_client.Reset(); diff --git a/chromium/ui/base/ime/text_input_client.h b/chromium/ui/base/ime/text_input_client.h index 390a96bad17..552208c30fa 100644 --- a/chromium/ui/base/ime/text_input_client.h +++ b/chromium/ui/base/ime/text_input_client.h @@ -5,7 +5,9 @@ #ifndef UI_BASE_IME_TEXT_INPUT_CLIENT_H_ #define UI_BASE_IME_TEXT_INPUT_CLIENT_H_ -#include "base/basictypes.h" +#include <stddef.h> +#include <stdint.h> + #include "base/i18n/rtl.h" #include "base/strings/string16.h" #include "ui/base/ime/composition_text.h" @@ -21,6 +23,8 @@ class Rect; namespace ui { +class KeyEvent; + // An interface implemented by a View that needs text input support. class UI_BASE_IME_EXPORT TextInputClient { public: @@ -46,14 +50,14 @@ class UI_BASE_IME_EXPORT TextInputClient { virtual void InsertText(const base::string16& text) = 0; // Inserts a single char at the insertion point. Unlike above InsertText() - // method, this method has an extra |flags| parameter indicating the modifier - // key states when the character is generated. This method should only be + // method, this method takes an |event| parameter indicating + // the event that was unprocessed. This method should only be // called when a key press is not handled by the input method but still // generates a character (eg. by the keyboard driver). In another word, the // preceding key press event should not be a VKEY_PROCESSKEY. // This method will be called whenever a char is generated by the keyboard, // even if the current text input type is TEXT_INPUT_TYPE_NONE. - virtual void InsertChar(base::char16 ch, int flags) = 0; + virtual void InsertChar(const ui::KeyEvent& event) = 0; // Input context information ------------------------------------------------- @@ -91,7 +95,7 @@ class UI_BASE_IME_EXPORT TextInputClient { // (Density Independent Pixel). // TODO(ime): Have a clear spec whether the returned value is DIP or not. // http://crbug.com/360334 - virtual bool GetCompositionCharacterBounds(uint32 index, + virtual bool GetCompositionCharacterBounds(uint32_t index, gfx::Rect* rect) const = 0; // Returns true if there is composition text. diff --git a/chromium/ui/base/ime/ui_base_ime.gyp b/chromium/ui/base/ime/ui_base_ime.gyp index 176404167aa..22c3e720148 100644 --- a/chromium/ui/base/ime/ui_base_ime.gyp +++ b/chromium/ui/base/ime/ui_base_ime.gyp @@ -36,16 +36,13 @@ 'chromeos/character_composer.h', 'chromeos/component_extension_ime_manager.cc', 'chromeos/component_extension_ime_manager.h', - 'chromeos/composition_text_chromeos.cc', - 'chromeos/composition_text_chromeos.h', 'chromeos/extension_ime_util.cc', 'chromeos/extension_ime_util.h', 'chromeos/fake_ime_keyboard.cc', 'chromeos/fake_ime_keyboard.h', 'chromeos/fake_input_method_delegate.cc', 'chromeos/fake_input_method_delegate.h', - 'chromeos/ime_bridge.cc', - 'chromeos/ime_bridge.h', + 'chromeos/ime_candidate_window_handler_interface.h', 'chromeos/ime_keyboard.cc', 'chromeos/ime_keyboard.h', 'chromeos/ime_keyboard_ozone.cc', @@ -74,6 +71,12 @@ 'composition_text_util_pango.cc', 'composition_text_util_pango.h', 'composition_underline.h', + 'ime_bridge.cc', + 'ime_bridge.h', + 'ime_engine_handler_interface.cc', + 'ime_engine_handler_interface.h', + 'ime_engine_observer.h', + 'ime_input_context_handler_interface.h', 'infolist_entry.cc', 'infolist_entry.h', 'input_method.h', diff --git a/chromium/ui/base/ime/win/imm32_manager.cc b/chromium/ui/base/ime/win/imm32_manager.cc index 4fc176613c1..853bf3ff26a 100644 --- a/chromium/ui/base/ime/win/imm32_manager.cc +++ b/chromium/ui/base/ime/win/imm32_manager.cc @@ -4,7 +4,9 @@ #include "ui/base/ime/win/imm32_manager.h" -#include "base/basictypes.h" +#include <stdint.h> + +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "base/strings/string_util.h" @@ -70,9 +72,9 @@ void GetCompositionUnderlines(HIMC imm_context, ui::CompositionUnderlines* underlines) { int clause_size = ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, NULL, 0); - int clause_length = clause_size / sizeof(uint32); + int clause_length = clause_size / sizeof(uint32_t); if (clause_length) { - scoped_ptr<uint32[]> clause_data(new uint32[clause_length]); + scoped_ptr<uint32_t[]> clause_data(new uint32_t[clause_length]); if (clause_data.get()) { ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, clause_data.get(), clause_size); @@ -85,8 +87,8 @@ void GetCompositionUnderlines(HIMC imm_context, underline.background_color = SK_ColorTRANSPARENT; // Use thick underline for the target clause. - if (underline.start_offset >= static_cast<uint32>(target_start) && - underline.end_offset <= static_cast<uint32>(target_end)) { + if (underline.start_offset >= static_cast<uint32_t>(target_start) && + underline.end_offset <= static_cast<uint32_t>(target_end)) { underline.thick = true; } underlines->push_back(underline); @@ -327,19 +329,19 @@ void IMM32Manager::GetCompositionInfo(HIMC imm_context, LPARAM lparam, underline.background_color = SK_ColorTRANSPARENT; if (target_start > 0) { underline.start_offset = 0U; - underline.end_offset = static_cast<uint32>(target_start); + underline.end_offset = static_cast<uint32_t>(target_start); underline.thick = false; composition->underlines.push_back(underline); } if (target_end > target_start) { - underline.start_offset = static_cast<uint32>(target_start); - underline.end_offset = static_cast<uint32>(target_end); + underline.start_offset = static_cast<uint32_t>(target_start); + underline.end_offset = static_cast<uint32_t>(target_end); underline.thick = true; composition->underlines.push_back(underline); } if (target_end < length) { - underline.start_offset = static_cast<uint32>(target_end); - underline.end_offset = static_cast<uint32>(length); + underline.start_offset = static_cast<uint32_t>(target_end); + underline.end_offset = static_cast<uint32_t>(length); underline.thick = false; composition->underlines.push_back(underline); } diff --git a/chromium/ui/base/ime/win/imm32_manager.h b/chromium/ui/base/ime/win/imm32_manager.h index 0665919aa15..b0fb1cda852 100644 --- a/chromium/ui/base/ime/win/imm32_manager.h +++ b/chromium/ui/base/ime/win/imm32_manager.h @@ -10,8 +10,8 @@ #include <string> #include <vector> -#include "base/basictypes.h" #include "base/i18n/rtl.h" +#include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/ui_base_ime_export.h" diff --git a/chromium/ui/base/ime/win/tsf_input_scope.cc b/chromium/ui/base/ime/win/tsf_input_scope.cc index a1ba89a6c23..347eea8d68c 100644 --- a/chromium/ui/base/ime/win/tsf_input_scope.cc +++ b/chromium/ui/base/ime/win/tsf_input_scope.cc @@ -4,11 +4,13 @@ #include "ui/base/ime/win/tsf_input_scope.h" -#include <algorithm> +#include <stddef.h> #include "base/compiler_specific.h" #include "base/logging.h" +#include "base/macros.h" #include "base/message_loop/message_loop.h" +#include "base/stl_util.h" #include "base/win/windows_version.h" namespace ui { @@ -22,8 +24,7 @@ void AppendNonTrivialInputScope(std::vector<InputScope>* input_scopes, if (input_scope == IS_DEFAULT) return; - if (std::find(input_scopes->begin(), input_scopes->end(), input_scope) != - input_scopes->end()) + if (ContainsValue(*input_scopes, input_scope)) return; input_scopes->push_back(input_scope); diff --git a/chromium/ui/base/ime/win/tsf_input_scope.h b/chromium/ui/base/ime/win/tsf_input_scope.h index d5caac390eb..e11e5de3ac8 100644 --- a/chromium/ui/base/ime/win/tsf_input_scope.h +++ b/chromium/ui/base/ime/win/tsf_input_scope.h @@ -9,7 +9,6 @@ #include <Windows.h> #include <vector> -#include "base/basictypes.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" #include "ui/base/ime/ui_base_ime_export.h" diff --git a/chromium/ui/base/ime/win/tsf_input_scope_unittest.cc b/chromium/ui/base/ime/win/tsf_input_scope_unittest.cc index de6ede17ffd..ed36a1806f7 100644 --- a/chromium/ui/base/ime/win/tsf_input_scope_unittest.cc +++ b/chromium/ui/base/ime/win/tsf_input_scope_unittest.cc @@ -5,6 +5,7 @@ #include "ui/base/ime/win/tsf_input_scope.h" #include <InputScope.h> +#include <stddef.h> #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/ui/base/ios/cru_context_menu_controller.mm b/chromium/ui/base/ios/cru_context_menu_controller.mm index 27ce9ee2580..f615c017b06 100644 --- a/chromium/ui/base/ios/cru_context_menu_controller.mm +++ b/chromium/ui/base/ios/cru_context_menu_controller.mm @@ -24,11 +24,11 @@ CGFloat GetScreenHeight() { switch ([[UIApplication sharedApplication] statusBarOrientation]) { case UIInterfaceOrientationLandscapeLeft: case UIInterfaceOrientationLandscapeRight: - return CGRectGetWidth([[UIScreen mainScreen] applicationFrame]); + return CGRectGetWidth([[UIScreen mainScreen] bounds]); case UIInterfaceOrientationPortraitUpsideDown: case UIInterfaceOrientationPortrait: case UIInterfaceOrientationUnknown: - return CGRectGetHeight([[UIScreen mainScreen] applicationFrame]); + return CGRectGetHeight([[UIScreen mainScreen] bounds]); } } diff --git a/chromium/ui/base/l10n/formatter.cc b/chromium/ui/base/l10n/formatter.cc index 298646d9e2c..94a83a49a03 100644 --- a/chromium/ui/base/l10n/formatter.cc +++ b/chromium/ui/base/l10n/formatter.cc @@ -4,6 +4,8 @@ #include "ui/base/l10n/formatter.h" +#include <limits.h> + #include <vector> #include "base/logging.h" @@ -151,7 +153,7 @@ scoped_ptr<icu::PluralRules> BuildPluralRules() { rules.reset(icu::PluralRules::createRules(fallback_rules, err)); DCHECK(U_SUCCESS(err)); } - return rules.Pass(); + return rules; } void FormatNumberInPlural(const icu::MessageFormat& format, int number, @@ -242,7 +244,7 @@ scoped_ptr<icu::MessageFormat> Formatter::CreateFallbackFormat( scoped_ptr<icu::MessageFormat> format( new icu::MessageFormat(pattern, error)); DCHECK(U_SUCCESS(error)); - return format.Pass(); + return format; } scoped_ptr<icu::MessageFormat> Formatter::InitFormat( @@ -254,7 +256,7 @@ scoped_ptr<icu::MessageFormat> Formatter::InitFormat( icu::UnicodeString(FALSE, pattern.data(), pattern.length()), error)); DCHECK(U_SUCCESS(error)); if (format.get()) - return format.Pass(); + return format; } scoped_ptr<icu::PluralRules> rules(BuildPluralRules()); diff --git a/chromium/ui/base/l10n/formatter.h b/chromium/ui/base/l10n/formatter.h index fcd410f39e0..fa3936c6648 100644 --- a/chromium/ui/base/l10n/formatter.h +++ b/chromium/ui/base/l10n/formatter.h @@ -8,8 +8,8 @@ #ifndef UI_BASE_L10N_FORMATTER_H_ #define UI_BASE_L10N_FORMATTER_H_ -#include "base/basictypes.h" #include "base/lazy_instance.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/icu/source/i18n/unicode/msgfmt.h" diff --git a/chromium/ui/base/l10n/l10n_util.cc b/chromium/ui/base/l10n/l10n_util.cc index c054b727bcd..c3e850da221 100644 --- a/chromium/ui/base/l10n/l10n_util.cc +++ b/chromium/ui/base/l10n/l10n_util.cc @@ -17,6 +17,7 @@ #include "base/i18n/rtl.h" #include "base/i18n/string_compare.h" #include "base/lazy_instance.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" @@ -820,7 +821,7 @@ base::string16 GetStringFUTF16Int(int message_id, int a) { return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::IntToString(a))); } -base::string16 GetStringFUTF16Int(int message_id, int64 a) { +base::string16 GetStringFUTF16Int(int message_id, int64_t a) { return GetStringFUTF16(message_id, base::UTF8ToUTF16(base::Int64ToString(a))); } diff --git a/chromium/ui/base/l10n/l10n_util.h b/chromium/ui/base/l10n/l10n_util.h index 9317556260f..c7f04f408cb 100644 --- a/chromium/ui/base/l10n/l10n_util.h +++ b/chromium/ui/base/l10n/l10n_util.h @@ -8,10 +8,14 @@ #ifndef UI_BASE_L10N_L10N_UTIL_H_ #define UI_BASE_L10N_L10N_UTIL_H_ +#include <stddef.h> +#include <stdint.h> + #include <string> #include <vector> #include "base/strings/string16.h" +#include "build/build_config.h" #include "ui/base/ui_base_export.h" #if defined(OS_MACOSX) @@ -160,7 +164,7 @@ UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, // Convenience functions to get a string with a single number as a parameter. UI_BASE_EXPORT base::string16 GetStringFUTF16Int(int message_id, int a); -base::string16 GetStringFUTF16Int(int message_id, int64 a); +base::string16 GetStringFUTF16Int(int message_id, int64_t a); // Get a resource string using |number| with a locale-specific plural rule. // |message_id| points to a message in the ICU syntax. diff --git a/chromium/ui/base/l10n/l10n_util_android.cc b/chromium/ui/base/l10n/l10n_util_android.cc index a5685416e00..6261969beb6 100644 --- a/chromium/ui/base/l10n/l10n_util_android.cc +++ b/chromium/ui/base/l10n/l10n_util_android.cc @@ -4,6 +4,8 @@ #include "ui/base/l10n/l10n_util_android.h" +#include <stdint.h> + #include "base/android/jni_android.h" #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" diff --git a/chromium/ui/base/l10n/l10n_util_collator.h b/chromium/ui/base/l10n/l10n_util_collator.h index 9b5322547b3..d2b95f26ae1 100644 --- a/chromium/ui/base/l10n/l10n_util_collator.h +++ b/chromium/ui/base/l10n/l10n_util_collator.h @@ -5,6 +5,8 @@ #ifndef UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ #define UI_BASE_L10N_L10N_UTIL_COLLATOR_H_ +#include <stddef.h> + #include <algorithm> #include <functional> #include <string> diff --git a/chromium/ui/base/l10n/l10n_util_mac.h b/chromium/ui/base/l10n/l10n_util_mac.h index c1ef16389fd..42f774d08a4 100644 --- a/chromium/ui/base/l10n/l10n_util_mac.h +++ b/chromium/ui/base/l10n/l10n_util_mac.h @@ -5,10 +5,11 @@ #ifndef UI_BASE_L10N_L10N_UTIL_MAC_H_ #define UI_BASE_L10N_L10N_UTIL_MAC_H_ +#include <stddef.h> + #include <string> #include <vector> -#include "base/basictypes.h" #include "base/strings/string16.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/l10n/l10n_util_mac_unittest.mm b/chromium/ui/base/l10n/l10n_util_mac_unittest.mm index adb0c57a7ab..78401554302 100644 --- a/chromium/ui/base/l10n/l10n_util_mac_unittest.mm +++ b/chromium/ui/base/l10n/l10n_util_mac_unittest.mm @@ -3,7 +3,9 @@ // found in the LICENSE file. #import <Foundation/Foundation.h> +#include <stddef.h> +#include "base/macros.h" #include "base/strings/sys_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" diff --git a/chromium/ui/base/l10n/l10n_util_posix.cc b/chromium/ui/base/l10n/l10n_util_posix.cc index 6415ff82ea1..b57e78da62f 100644 --- a/chromium/ui/base/l10n/l10n_util_posix.cc +++ b/chromium/ui/base/l10n/l10n_util_posix.cc @@ -2,10 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> + #include <string> +#include "base/macros.h" +#include "build/build_config.h" + #if defined(OS_CHROMEOS) -#include "base/basictypes.h" #include "base/strings/string_util.h" #endif diff --git a/chromium/ui/base/l10n/l10n_util_unittest.cc b/chromium/ui/base/l10n/l10n_util_unittest.cc index 43c9ad47213..3719a1aa1e7 100644 --- a/chromium/ui/base/l10n/l10n_util_unittest.cc +++ b/chromium/ui/base/l10n/l10n_util_unittest.cc @@ -2,22 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "build/build_config.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -#include <cstdlib> -#endif +#include <stddef.h> -#include "base/basictypes.h" #include "base/environment.h" #include "base/files/file_util.h" #include "base/i18n/case_conversion.h" #include "base/i18n/rtl.h" +#include "base/macros.h" #include "base/path_service.h" #include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/test/scoped_path_override.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" #include "third_party/icu/source/common/unicode/locid.h" @@ -25,6 +22,10 @@ #include "ui/base/l10n/l10n_util_collator.h" #include "ui/base/ui_base_paths.h" +#if defined(OS_POSIX) && !defined(OS_MACOSX) +#include <cstdlib> +#endif + #if defined(OS_WIN) #include "base/win/windows_version.h" #endif diff --git a/chromium/ui/base/l10n/l10n_util_win.cc b/chromium/ui/base/l10n/l10n_util_win.cc index efc43e2edd0..d86e02fee51 100644 --- a/chromium/ui/base/l10n/l10n_util_win.cc +++ b/chromium/ui/base/l10n/l10n_util_win.cc @@ -10,6 +10,7 @@ #include "base/i18n/rtl.h" #include "base/lazy_instance.h" +#include "base/macros.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" diff --git a/chromium/ui/base/l10n/time_format.h b/chromium/ui/base/l10n/time_format.h index 38da936d617..9fda463c9e2 100644 --- a/chromium/ui/base/l10n/time_format.h +++ b/chromium/ui/base/l10n/time_format.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_L10N_TIME_FORMAT_H_ #define UI_BASE_L10N_TIME_FORMAT_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/layout.cc b/chromium/ui/base/layout.cc index e49c24bed9b..f4ebc0162c5 100644 --- a/chromium/ui/base/layout.cc +++ b/chromium/ui/base/layout.cc @@ -4,13 +4,15 @@ #include "ui/base/layout.h" +#include <stddef.h> + #include <algorithm> #include <cmath> #include <limits> -#include "base/basictypes.h" #include "base/command_line.h" #include "base/logging.h" +#include "base/macros.h" #include "build/build_config.h" #include "ui/base/touch/touch_device.h" #include "ui/base/ui_base_switches.h" @@ -18,12 +20,6 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/screen.h" -#if defined(OS_WIN) -#include "base/win/metro.h" -#include "ui/gfx/win/dpi.h" -#include <Windows.h> -#endif // defined(OS_WIN) - namespace ui { namespace { @@ -80,14 +76,6 @@ ScaleFactor GetSupportedScaleFactor(float scale) { return closest_match; } -float GetImageScale(ScaleFactor scale_factor) { -#if defined(OS_WIN) - return gfx::GetDPIScale(); -#else - return GetScaleForScaleFactor(scale_factor); -#endif -} - float GetScaleForScaleFactor(ScaleFactor scale_factor) { return kScaleFactorScales[scale_factor]; } diff --git a/chromium/ui/base/layout.h b/chromium/ui/base/layout.h index c0ca3cb65e4..8b528580f74 100644 --- a/chromium/ui/base/layout.h +++ b/chromium/ui/base/layout.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/macros.h" #include "build/build_config.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" diff --git a/chromium/ui/base/layout_unittest.cc b/chromium/ui/base/layout_unittest.cc index 070247079ef..4b0c5b1542c 100644 --- a/chromium/ui/base/layout_unittest.cc +++ b/chromium/ui/base/layout_unittest.cc @@ -4,6 +4,7 @@ #include "ui/base/layout.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_CHROMEOS) diff --git a/chromium/ui/base/models/button_menu_item_model.h b/chromium/ui/base/models/button_menu_item_model.h index 01666fe7155..9c78b5986c8 100644 --- a/chromium/ui/base/models/button_menu_item_model.h +++ b/chromium/ui/base/models/button_menu_item_model.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/models/list_model.h b/chromium/ui/base/models/list_model.h index 6ed660fe4ec..f8212f22a69 100644 --- a/chromium/ui/base/models/list_model.h +++ b/chromium/ui/base/models/list_model.h @@ -5,8 +5,12 @@ #ifndef UI_BASE_MODELS_LIST_MODEL_H_ #define UI_BASE_MODELS_LIST_MODEL_H_ -#include "base/basictypes.h" +#include <stddef.h> + +#include <utility> + #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/observer_list.h" @@ -60,7 +64,7 @@ class ListModel { // Removes and deletes all items from the model. void DeleteAll() { - ScopedVector<ItemType> to_be_deleted(items_.Pass()); + ScopedVector<ItemType> to_be_deleted(std::move(items_)); NotifyItemsRemoved(0, to_be_deleted.size()); } diff --git a/chromium/ui/base/models/list_model_unittest.cc b/chromium/ui/base/models/list_model_unittest.cc index 8075a4a0e69..b76fe0cc5b7 100644 --- a/chromium/ui/base/models/list_model_unittest.cc +++ b/chromium/ui/base/models/list_model_unittest.cc @@ -4,8 +4,10 @@ #include "ui/base/models/list_model.h" -#include "base/basictypes.h" +#include <stddef.h> + #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/ui/base/models/list_selection_model.h b/chromium/ui/base/models/list_selection_model.h index 234714dd2fa..6cd79528885 100644 --- a/chromium/ui/base/models/list_selection_model.h +++ b/chromium/ui/base/models/list_selection_model.h @@ -5,9 +5,11 @@ #ifndef UI_BASE_MODELS_LIST_SELECTION_MODEL_H_ #define UI_BASE_MODELS_LIST_SELECTION_MODEL_H_ +#include <stddef.h> + #include <vector> -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/models/list_selection_model_unittest.cc b/chromium/ui/base/models/list_selection_model_unittest.cc index 7f7a712a68c..bcfe5641381 100644 --- a/chromium/ui/base/models/list_selection_model_unittest.cc +++ b/chromium/ui/base/models/list_selection_model_unittest.cc @@ -4,6 +4,8 @@ #include "ui/base/models/list_selection_model.h" +#include <stddef.h> + #include <algorithm> #include <string> diff --git a/chromium/ui/base/models/simple_combobox_model.h b/chromium/ui/base/models/simple_combobox_model.h index beaa04a6b84..06e534ae055 100644 --- a/chromium/ui/base/models/simple_combobox_model.h +++ b/chromium/ui/base/models/simple_combobox_model.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_MODELS_SIMPLE_COMBOBOX_MODEL_H_ #define UI_BASE_MODELS_SIMPLE_COMBOBOX_MODEL_H_ +#include "base/macros.h" #include "ui/base/models/combobox_model.h" #include <vector> diff --git a/chromium/ui/base/models/simple_menu_model.cc b/chromium/ui/base/models/simple_menu_model.cc index a8bfdb8eaba..3fd26fa683b 100644 --- a/chromium/ui/base/models/simple_menu_model.cc +++ b/chromium/ui/base/models/simple_menu_model.cc @@ -4,6 +4,8 @@ #include "ui/base/models/simple_menu_model.h" +#include <stddef.h> + #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "ui/base/l10n/l10n_util.h" diff --git a/chromium/ui/base/models/simple_menu_model.h b/chromium/ui/base/models/simple_menu_model.h index 9691d3baab6..639830d1071 100644 --- a/chromium/ui/base/models/simple_menu_model.h +++ b/chromium/ui/base/models/simple_menu_model.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/strings/string16.h" #include "ui/base/models/menu_model.h" diff --git a/chromium/ui/base/models/tree_node_iterator.h b/chromium/ui/base/models/tree_node_iterator.h index f8664dfa760..3a80e7c89c3 100644 --- a/chromium/ui/base/models/tree_node_iterator.h +++ b/chromium/ui/base/models/tree_node_iterator.h @@ -7,9 +7,9 @@ #include <stack> -#include "base/basictypes.h" #include "base/callback.h" #include "base/logging.h" +#include "base/macros.h" namespace ui { diff --git a/chromium/ui/base/models/tree_node_model.h b/chromium/ui/base/models/tree_node_model.h index 5118578a4e3..9606dc8119c 100644 --- a/chromium/ui/base/models/tree_node_model.h +++ b/chromium/ui/base/models/tree_node_model.h @@ -5,12 +5,14 @@ #ifndef UI_BASE_MODELS_TREE_NODE_MODEL_H_ #define UI_BASE_MODELS_TREE_NODE_MODEL_H_ +#include <stddef.h> + #include <algorithm> #include <vector> -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/observer_list.h" diff --git a/chromium/ui/base/models/tree_node_model_unittest.cc b/chromium/ui/base/models/tree_node_model_unittest.cc index f83569f2aba..da5f8f998e7 100644 --- a/chromium/ui/base/models/tree_node_model_unittest.cc +++ b/chromium/ui/base/models/tree_node_model_unittest.cc @@ -4,8 +4,8 @@ #include "ui/base/models/tree_node_model.h" -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "base/strings/stringprintf.h" diff --git a/chromium/ui/base/nine_image_painter_factory.cc b/chromium/ui/base/nine_image_painter_factory.cc index 3b47160e31f..691e4ae8817 100644 --- a/chromium/ui/base/nine_image_painter_factory.cc +++ b/chromium/ui/base/nine_image_painter_factory.cc @@ -4,6 +4,8 @@ #include "ui/base/nine_image_painter_factory.h" +#include <stddef.h> + #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/nine_image_painter.h" diff --git a/chromium/ui/base/nine_image_painter_factory.h b/chromium/ui/base/nine_image_painter_factory.h index d09f95c8428..5978c0f1134 100644 --- a/chromium/ui/base/nine_image_painter_factory.h +++ b/chromium/ui/base/nine_image_painter_factory.h @@ -13,8 +13,8 @@ x ## _LEFT, x ## _CENTER, x ## _RIGHT, \ x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, } -// Defines a empty image for used in macro for creating image grid for a ring of -// eight images. +// Defines an empty image for use in macros for creating an image grid for a +// ring of eight images. #define EMPTY_IMAGE 0 // A macro to define arrays of IDR constants used with CreateImageGridPainter diff --git a/chromium/ui/base/page_transition_types.cc b/chromium/ui/base/page_transition_types.cc index 62c4e5aaba2..d7623f500f1 100644 --- a/chromium/ui/base/page_transition_types.cc +++ b/chromium/ui/base/page_transition_types.cc @@ -20,13 +20,13 @@ PageTransition PageTransitionStripQualifier(PageTransition type) { return static_cast<PageTransition>(type & ~PAGE_TRANSITION_QUALIFIER_MASK); } -bool PageTransitionIsValidType(int32 type) { +bool PageTransitionIsValidType(int32_t type) { PageTransition t = PageTransitionStripQualifier( static_cast<PageTransition>(type)); return (t <= PAGE_TRANSITION_LAST_CORE); } -PageTransition PageTransitionFromInt(int32 type) { +PageTransition PageTransitionFromInt(int32_t type) { if (!PageTransitionIsValidType(type)) { NOTREACHED() << "Invalid transition type " << type; @@ -37,7 +37,7 @@ PageTransition PageTransitionFromInt(int32 type) { } bool PageTransitionIsMainFrame(PageTransition type) { - int32 t = PageTransitionStripQualifier(type); + int32_t t = PageTransitionStripQualifier(type); return (t != PAGE_TRANSITION_AUTO_SUBFRAME && t != PAGE_TRANSITION_MANUAL_SUBFRAME); } @@ -51,12 +51,12 @@ bool PageTransitionIsNewNavigation(PageTransition type) { !PageTransitionCoreTypeIs(type, PAGE_TRANSITION_RELOAD); } -int32 PageTransitionGetQualifier(PageTransition type) { +int32_t PageTransitionGetQualifier(PageTransition type) { return type & PAGE_TRANSITION_QUALIFIER_MASK; } bool PageTransitionIsWebTriggerable(PageTransition type) { - int32 t = PageTransitionStripQualifier(type); + int32_t t = PageTransitionStripQualifier(type); switch (t) { case PAGE_TRANSITION_LINK: case PAGE_TRANSITION_AUTO_SUBFRAME: @@ -68,7 +68,7 @@ bool PageTransitionIsWebTriggerable(PageTransition type) { } const char* PageTransitionGetCoreTransitionString(PageTransition type) { - int32 t = PageTransitionStripQualifier(type); + int32_t t = PageTransitionStripQualifier(type); switch (t) { case PAGE_TRANSITION_LINK: return "link"; case PAGE_TRANSITION_TYPED: return "typed"; diff --git a/chromium/ui/base/page_transition_types.h b/chromium/ui/base/page_transition_types.h index 4e54f92e518..ef0bb48da36 100644 --- a/chromium/ui/base/page_transition_types.h +++ b/chromium/ui/base/page_transition_types.h @@ -5,7 +5,8 @@ #ifndef UI_BASE_PAGE_TRANSITION_TYPES_H_ #define UI_BASE_PAGE_TRANSITION_TYPES_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "ui/base/ui_base_export.h" namespace ui { @@ -154,9 +155,9 @@ UI_BASE_EXPORT bool PageTransitionCoreTypeIs(PageTransition lhs, UI_BASE_EXPORT PageTransition PageTransitionStripQualifier( PageTransition type); -bool PageTransitionIsValidType(int32 type); +bool PageTransitionIsValidType(int32_t type); -UI_BASE_EXPORT PageTransition PageTransitionFromInt(int32 type); +UI_BASE_EXPORT PageTransition PageTransitionFromInt(int32_t type); // Returns true if the given transition is a top-level frame transition, or // false if the transition was for a subframe. @@ -170,7 +171,7 @@ UI_BASE_EXPORT bool PageTransitionIsRedirect(PageTransition type); UI_BASE_EXPORT bool PageTransitionIsNewNavigation(PageTransition type); // Return the qualifier -UI_BASE_EXPORT int32 PageTransitionGetQualifier(PageTransition type); +UI_BASE_EXPORT int32_t PageTransitionGetQualifier(PageTransition type); // Returns true if the transition can be triggered by the web instead of // through UI or similar. diff --git a/chromium/ui/base/resource/data_pack.cc b/chromium/ui/base/resource/data_pack.cc index 09d73d79c59..245c1b7c842 100644 --- a/chromium/ui/base/resource/data_pack.cc +++ b/chromium/ui/base/resource/data_pack.cc @@ -5,6 +5,7 @@ #include "ui/base/resource/data_pack.h" #include <errno.h> +#include <utility> #include "base/files/file_util.h" #include "base/files/memory_mapped_file.h" @@ -18,17 +19,17 @@ namespace { -static const uint32 kFileFormatVersion = 4; +static const uint32_t kFileFormatVersion = 4; // Length of file header: version, entry count and text encoding type. -static const size_t kHeaderLength = 2 * sizeof(uint32) + sizeof(uint8); +static const size_t kHeaderLength = 2 * sizeof(uint32_t) + sizeof(uint8_t); #pragma pack(push,2) struct DataPackEntry { - uint16 resource_id; - uint32 file_offset; + uint16_t resource_id; + uint32_t file_offset; static int CompareById(const void* void_key, const void* void_entry) { - uint16 key = *reinterpret_cast<const uint16*>(void_key); + uint16_t key = *reinterpret_cast<const uint16_t*>(void_key); const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>(void_entry); if (key < entry->resource_id) { @@ -86,7 +87,7 @@ bool DataPack::LoadFromPath(const base::FilePath& path) { } bool DataPack::LoadFromFile(base::File file) { - return LoadFromFileRegion(file.Pass(), + return LoadFromFileRegion(std::move(file), base::MemoryMappedFile::Region::kWholeFile); } @@ -94,7 +95,7 @@ bool DataPack::LoadFromFileRegion( base::File file, const base::MemoryMappedFile::Region& region) { mmap_.reset(new base::MemoryMappedFile); - if (!mmap_->Initialize(file.Pass(), region)) { + if (!mmap_->Initialize(std::move(file), region)) { DLOG(ERROR) << "Failed to mmap datapack"; UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, LOAD_ERRORS_COUNT); @@ -115,9 +116,9 @@ bool DataPack::LoadImpl() { } // Parse the header of the file. - // First uint32: version; second: resource count; - const uint32* ptr = reinterpret_cast<const uint32*>(mmap_->data()); - uint32 version = ptr[0]; + // First uint32_t: version; second: resource count; + const uint32_t* ptr = reinterpret_cast<const uint32_t*>(mmap_->data()); + uint32_t version = ptr[0]; if (version != kFileFormatVersion) { LOG(ERROR) << "Bad data pack version: got " << version << ", expected " << kFileFormatVersion; @@ -129,7 +130,7 @@ bool DataPack::LoadImpl() { resource_count_ = ptr[1]; // third: text encoding. - const uint8* ptr_encoding = reinterpret_cast<const uint8*>(ptr + 2); + const uint8_t* ptr_encoding = reinterpret_cast<const uint8_t*>(ptr + 2); text_encoding_type_ = static_cast<TextEncodingType>(*ptr_encoding); if (text_encoding_type_ != UTF8 && text_encoding_type_ != UTF16 && text_encoding_type_ != BINARY) { @@ -171,12 +172,12 @@ bool DataPack::LoadImpl() { return true; } -bool DataPack::HasResource(uint16 resource_id) const { +bool DataPack::HasResource(uint16_t resource_id) const { return !!bsearch(&resource_id, mmap_->data() + kHeaderLength, resource_count_, sizeof(DataPackEntry), DataPackEntry::CompareById); } -bool DataPack::GetStringPiece(uint16 resource_id, +bool DataPack::GetStringPiece(uint16_t resource_id, base::StringPiece* data) const { // It won't be hard to make this endian-agnostic, but it's not worth // bothering to do right now. @@ -216,7 +217,7 @@ bool DataPack::GetStringPiece(uint16 resource_id, } base::RefCountedStaticMemory* DataPack::GetStaticMemory( - uint16 resource_id) const { + uint16_t resource_id) const { base::StringPiece piece; if (!GetStringPiece(resource_id, &piece)) return NULL; @@ -242,7 +243,7 @@ void DataPack::CheckForDuplicateResources( for (size_t i = 0; i < resource_count_ + 1; ++i) { const DataPackEntry* entry = reinterpret_cast<const DataPackEntry*>( mmap_->data() + kHeaderLength + (i * sizeof(DataPackEntry))); - const uint16 resource_id = entry->resource_id; + const uint16_t resource_id = entry->resource_id; const float resource_scale = GetScaleForScaleFactor(scale_factor_); for (const ResourceHandle* handle : packs) { if (HasOnlyMaterialDesignAssets() != @@ -261,7 +262,7 @@ void DataPack::CheckForDuplicateResources( // static bool DataPack::WritePack(const base::FilePath& path, - const std::map<uint16, base::StringPiece>& resources, + const std::map<uint16_t, base::StringPiece>& resources, TextEncodingType textEncodingType) { FILE* file = base::OpenFile(path, "wb"); if (!file) @@ -275,7 +276,7 @@ bool DataPack::WritePack(const base::FilePath& path, // Note: the python version of this function explicitly sorted keys, but // std::map is a sorted associative container, we shouldn't have to do that. - uint32 entry_count = resources.size(); + uint32_t entry_count = resources.size(); if (fwrite(&entry_count, sizeof(entry_count), 1, file) != 1) { LOG(ERROR) << "Failed to write entry count"; base::CloseFile(file); @@ -290,21 +291,21 @@ bool DataPack::WritePack(const base::FilePath& path, return false; } - uint8 write_buffer = static_cast<uint8>(textEncodingType); - if (fwrite(&write_buffer, sizeof(uint8), 1, file) != 1) { + uint8_t write_buffer = static_cast<uint8_t>(textEncodingType); + if (fwrite(&write_buffer, sizeof(uint8_t), 1, file) != 1) { LOG(ERROR) << "Failed to write file text resources encoding"; base::CloseFile(file); return false; } - // Each entry is a uint16 + a uint32. We have an extra entry after the last - // item so we can compute the size of the list item. - uint32 index_length = (entry_count + 1) * sizeof(DataPackEntry); - uint32 data_offset = kHeaderLength + index_length; - for (std::map<uint16, base::StringPiece>::const_iterator it = + // Each entry is a uint16_t + a uint32_t. We have an extra entry after the + // last item so we can compute the size of the list item. + uint32_t index_length = (entry_count + 1) * sizeof(DataPackEntry); + uint32_t data_offset = kHeaderLength + index_length; + for (std::map<uint16_t, base::StringPiece>::const_iterator it = resources.begin(); it != resources.end(); ++it) { - uint16 resource_id = it->first; + uint16_t resource_id = it->first; if (fwrite(&resource_id, sizeof(resource_id), 1, file) != 1) { LOG(ERROR) << "Failed to write id for " << resource_id; base::CloseFile(file); @@ -322,7 +323,7 @@ bool DataPack::WritePack(const base::FilePath& path, // We place an extra entry after the last item that allows us to read the // size of the last item. - uint16 resource_id = 0; + uint16_t resource_id = 0; if (fwrite(&resource_id, sizeof(resource_id), 1, file) != 1) { LOG(ERROR) << "Failed to write extra resource id."; base::CloseFile(file); @@ -335,7 +336,7 @@ bool DataPack::WritePack(const base::FilePath& path, return false; } - for (std::map<uint16, base::StringPiece>::const_iterator it = + for (std::map<uint16_t, base::StringPiece>::const_iterator it = resources.begin(); it != resources.end(); ++it) { if (fwrite(it->second.data(), it->second.length(), 1, file) != 1) { diff --git a/chromium/ui/base/resource/data_pack.h b/chromium/ui/base/resource/data_pack.h index aed737b2d0c..b2d90684c0f 100644 --- a/chromium/ui/base/resource/data_pack.h +++ b/chromium/ui/base/resource/data_pack.h @@ -9,11 +9,14 @@ #ifndef UI_BASE_RESOURCE_DATA_PACK_H_ #define UI_BASE_RESOURCE_DATA_PACK_H_ +#include <stddef.h> +#include <stdint.h> + #include <map> -#include "base/basictypes.h" #include "base/files/file.h" #include "base/files/memory_mapped_file.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/strings/string_piece.h" @@ -52,15 +55,15 @@ class UI_BASE_EXPORT DataPack : public ResourceHandle { // |textEncodingType| specified. If no text resources are present, please // indicate BINARY. static bool WritePack(const base::FilePath& path, - const std::map<uint16, base::StringPiece>& resources, + const std::map<uint16_t, base::StringPiece>& resources, TextEncodingType textEncodingType); // ResourceHandle implementation: - bool HasResource(uint16 resource_id) const override; - bool GetStringPiece(uint16 resource_id, + bool HasResource(uint16_t resource_id) const override; + bool GetStringPiece(uint16_t resource_id, base::StringPiece* data) const override; base::RefCountedStaticMemory* GetStaticMemory( - uint16 resource_id) const override; + uint16_t resource_id) const override; TextEncodingType GetTextEncodingType() const override; ui::ScaleFactor GetScaleFactor() const override; bool HasOnlyMaterialDesignAssets() const override; diff --git a/chromium/ui/base/resource/data_pack_literal.cc b/chromium/ui/base/resource/data_pack_literal.cc index 672e55257eb..cf490868cca 100644 --- a/chromium/ui/base/resource/data_pack_literal.cc +++ b/chromium/ui/base/resource/data_pack_literal.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/basictypes.h" +#include <stddef.h> namespace ui { diff --git a/chromium/ui/base/resource/data_pack_unittest.cc b/chromium/ui/base/resource/data_pack_unittest.cc index b0932fcef8e..33d5e4161d7 100644 --- a/chromium/ui/base/resource/data_pack_unittest.cc +++ b/chromium/ui/base/resource/data_pack_unittest.cc @@ -2,14 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ui/base/resource/data_pack.h" + +#include <stddef.h> +#include <stdint.h> + +#include <utility> + #include "base/files/file.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/path_service.h" #include "base/strings/string_piece.h" +#include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/resource/data_pack.h" #include "ui/base/ui_base_paths.h" namespace ui { @@ -71,7 +78,7 @@ TEST(DataPackTest, LoadFromFile) { // Load the file through the data pack API. DataPack pack(SCALE_FACTOR_100P); - ASSERT_TRUE(pack.LoadFromFile(file.Pass())); + ASSERT_TRUE(pack.LoadFromFile(std::move(file))); base::StringPiece data; ASSERT_TRUE(pack.HasResource(4)); @@ -111,7 +118,7 @@ TEST(DataPackTest, LoadFromFileRegion) { // Load the file through the data pack API. DataPack pack(SCALE_FACTOR_100P); base::MemoryMappedFile::Region region = {sizeof(kPadding), kSamplePakSize}; - ASSERT_TRUE(pack.LoadFromFileRegion(file.Pass(), region)); + ASSERT_TRUE(pack.LoadFromFileRegion(std::move(file), region)); base::StringPiece data; ASSERT_TRUE(pack.HasResource(4)); @@ -159,7 +166,7 @@ TEST_P(DataPackTest, Write) { std::string four("four"); std::string fifteen("fifteen"); - std::map<uint16, base::StringPiece> resources; + std::map<uint16_t, base::StringPiece> resources; resources.insert(std::make_pair(1, base::StringPiece(one))); resources.insert(std::make_pair(2, base::StringPiece(two))); resources.insert(std::make_pair(15, base::StringPiece(fifteen))); @@ -200,7 +207,7 @@ TEST(DataPackTest, ModifiedWhileUsed) { // Load the file through the data pack API. DataPack pack(SCALE_FACTOR_100P); - ASSERT_TRUE(pack.LoadFromFile(file.Pass())); + ASSERT_TRUE(pack.LoadFromFile(std::move(file))); base::StringPiece data; ASSERT_TRUE(pack.HasResource(10)); diff --git a/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc b/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc index fa244ad7c81..cfc76b59493 100644 --- a/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc +++ b/chromium/ui/base/resource/material_design/material_design_controller_unittest.cc @@ -21,7 +21,7 @@ class MaterialDesignControllerTest : public testing::Test { ~MaterialDesignControllerTest() override; // testing::Test: - void TearDown() override; + void SetUp() override; private: DISALLOW_COPY_AND_ASSIGN(MaterialDesignControllerTest); @@ -33,10 +33,14 @@ MaterialDesignControllerTest::MaterialDesignControllerTest() { MaterialDesignControllerTest::~MaterialDesignControllerTest() { } -void MaterialDesignControllerTest::TearDown() { - testing::Test::TearDown(); +void MaterialDesignControllerTest::SetUp() { + testing::Test::SetUp(); - // Ensure other tests aren't polluted by a Mode set in these tests. + // Ensure other tests aren't polluted by a Mode set in these tests. The Mode + // has to be cleared in SetUp and not in TearDown because when the test suite + // starts up it triggers a call to ResourceBundle::LoadCommonResources() + // which calls MaterialDesignController::IsModeMaterial(), thereby + // initializing the mode and potentially causing the first test to fail. test::MaterialDesignControllerTestAPI::UninitializeMode(); } diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc index 6d0427158e6..a2aa5824a19 100644 --- a/chromium/ui/base/resource/resource_bundle.cc +++ b/chromium/ui/base/resource/resource_bundle.cc @@ -4,7 +4,10 @@ #include "ui/base/resource/resource_bundle.h" +#include <stdint.h> + #include <limits> +#include <utility> #include <vector> #include "base/big_endian.h" @@ -12,6 +15,7 @@ #include "base/files/file.h" #include "base/files/file_util.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/metrics/histogram.h" #include "base/path_service.h" @@ -39,6 +43,7 @@ #if defined(OS_ANDROID) #include "ui/base/resource/resource_bundle_android.h" +#include "ui/gfx/android/device_display_info.h" #endif #if defined(OS_CHROMEOS) @@ -176,7 +181,7 @@ void ResourceBundle::InitSharedInstanceWithPakFileRegion( const base::MemoryMappedFile::Region& region) { InitSharedInstance(NULL); scoped_ptr<DataPack> data_pack(new DataPack(SCALE_FACTOR_100P)); - if (!data_pack->LoadFromFileRegion(pak_file.Pass(), region)) { + if (!data_pack->LoadFromFileRegion(std::move(pak_file), region)) { NOTREACHED() << "failed to load pak file"; return; } @@ -242,8 +247,9 @@ void ResourceBundle::AddOptionalMaterialDesignDataPackFromPath( void ResourceBundle::AddDataPackFromFile(base::File file, ScaleFactor scale_factor) { - AddDataPackFromFileRegion( - file.Pass(), base::MemoryMappedFile::Region::kWholeFile, scale_factor); + AddDataPackFromFileRegion(std::move(file), + base::MemoryMappedFile::Region::kWholeFile, + scale_factor); } void ResourceBundle::AddDataPackFromFileRegion( @@ -252,7 +258,7 @@ void ResourceBundle::AddDataPackFromFileRegion( ScaleFactor scale_factor) { scoped_ptr<DataPack> data_pack( new DataPack(scale_factor)); - if (data_pack->LoadFromFileRegion(file.Pass(), region)) { + if (data_pack->LoadFromFileRegion(std::move(file), region)) { AddDataPack(data_pack.release()); } else { LOG(ERROR) << "Failed to load data pack from file." @@ -464,7 +470,7 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale( if (scale_factor != ui::SCALE_FACTOR_100P) { for (size_t i = 0; i < data_packs_.size(); i++) { if (data_packs_[i]->GetScaleFactor() == scale_factor && - data_packs_[i]->GetStringPiece(static_cast<uint16>(resource_id), + data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id), &data)) return data; } @@ -475,7 +481,7 @@ base::StringPiece ResourceBundle::GetRawDataResourceForScale( data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_200P || data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_300P || data_packs_[i]->GetScaleFactor() == ui::SCALE_FACTOR_NONE) && - data_packs_[i]->GetStringPiece(static_cast<uint16>(resource_id), + data_packs_[i]->GetStringPiece(static_cast<uint16_t>(resource_id), &data)) return data; } @@ -505,7 +511,7 @@ base::string16 ResourceBundle::GetLocalizedString(int message_id) { } base::StringPiece data; - if (!locale_resources_data_->GetStringPiece(static_cast<uint16>(message_id), + if (!locale_resources_data_->GetStringPiece(static_cast<uint16_t>(message_id), &data)) { // Fall back on the main data pack (shouldn't be any strings here except in // unittests). @@ -608,9 +614,13 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) { supported_scale_factors.push_back(SCALE_FACTOR_100P); #endif #if defined(OS_ANDROID) - const gfx::Display display = - gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); - const float display_density = display.device_scale_factor(); + float display_density; + if (gfx::Display::HasForceDeviceScaleFactor()) { + display_density = gfx::Display::GetForcedDeviceScaleFactor(); + } else { + gfx::DeviceDisplayInfo device_info; + display_density = device_info.GetDIPScale(); + } const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density); if (closest != SCALE_FACTOR_100P) supported_scale_factors.push_back(closest); @@ -646,11 +656,6 @@ void ResourceBundle::InitSharedInstance(Delegate* delegate) { supported_scale_factors.push_back(SCALE_FACTOR_100P); #endif ui::SetSupportedScaleFactors(supported_scale_factors); -#if defined(OS_WIN) - // Must be called _after_ supported scale factors are set since it - // uses them. - gfx::InitDeviceScaleFactor(gfx::GetDPIScale()); -#endif } void ResourceBundle::FreeImages() { @@ -820,7 +825,7 @@ bool ResourceBundle::LoadBitmap(const ResourceHandle& data_handle, bool* fell_back_to_1x) const { DCHECK(fell_back_to_1x); scoped_refptr<base::RefCountedMemory> memory( - data_handle.GetStaticMemory(static_cast<uint16>(resource_id))); + data_handle.GetStaticMemory(static_cast<uint16_t>(resource_id))); if (!memory.get()) return false; @@ -891,15 +896,16 @@ bool ResourceBundle::PNGContainsFallbackMarker(const unsigned char* buf, for (;;) { if (size - pos < kPngChunkMetadataSize) break; - uint32 length = 0; + uint32_t length = 0; base::ReadBigEndian(reinterpret_cast<const char*>(buf + pos), &length); if (size - pos - kPngChunkMetadataSize < length) break; - if (length == 0 && memcmp(buf + pos + sizeof(uint32), kPngScaleChunkType, - arraysize(kPngScaleChunkType)) == 0) { + if (length == 0 && + memcmp(buf + pos + sizeof(uint32_t), kPngScaleChunkType, + arraysize(kPngScaleChunkType)) == 0) { return true; } - if (memcmp(buf + pos + sizeof(uint32), kPngDataChunkType, + if (memcmp(buf + pos + sizeof(uint32_t), kPngDataChunkType, arraysize(kPngDataChunkType)) == 0) { // Stop looking for custom chunks, any custom chunks should be before an // IDAT chunk. diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h index 506515358ac..3e169a469bd 100644 --- a/chromium/ui/base/resource/resource_bundle.h +++ b/chromium/ui/base/resource/resource_bundle.h @@ -5,14 +5,16 @@ #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ +#include <stddef.h> + #include <map> #include <string> -#include "base/basictypes.h" #include "base/containers/hash_tables.h" #include "base/files/file_path.h" #include "base/files/memory_mapped_file.h" #include "base/gtest_prod_util.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/strings/string16.h" @@ -295,7 +297,10 @@ class UI_BASE_EXPORT ResourceBundle { FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetNativeImageNamed); FRIEND_TEST_ALL_PREFIXES(ResourceBundleImageTest, CountMaterialDesignDataPacksInResourceBundle); + FRIEND_TEST_ALL_PREFIXES(ResourceBundleMacImageTest, + CheckImageFromMaterialDesign); + friend class ResourceBundleMacImageTest; friend class ResourceBundleImageTest; friend class ResourceBundleTest; diff --git a/chromium/ui/base/resource/resource_bundle_android.h b/chromium/ui/base/resource/resource_bundle_android.h index a9d3b1d1c56..ffce054a383 100644 --- a/chromium/ui/base/resource/resource_bundle_android.h +++ b/chromium/ui/base/resource/resource_bundle_android.h @@ -8,7 +8,6 @@ #include <jni.h> #include <string> -#include "base/basictypes.h" #include "base/files/memory_mapped_file.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/resource/resource_bundle_ios.mm b/chromium/ui/base/resource/resource_bundle_ios.mm index 1cd00d1d368..88cf829c6dd 100644 --- a/chromium/ui/base/resource/resource_bundle_ios.mm +++ b/chromium/ui/base/resource/resource_bundle_ios.mm @@ -7,7 +7,6 @@ #import <QuartzCore/QuartzCore.h> #import <UIKit/UIKit.h> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/mac/bundle_locations.h" diff --git a/chromium/ui/base/resource/resource_bundle_mac.mm b/chromium/ui/base/resource/resource_bundle_mac.mm index eaa3929c44b..74d82615606 100644 --- a/chromium/ui/base/resource/resource_bundle_mac.mm +++ b/chromium/ui/base/resource/resource_bundle_mac.mm @@ -5,8 +5,8 @@ #include "ui/base/resource/resource_bundle.h" #import <AppKit/AppKit.h> +#include <stddef.h> -#include "base/basictypes.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/mac/bundle_locations.h" @@ -14,6 +14,7 @@ #include "base/memory/ref_counted_memory.h" #include "base/strings/sys_string_conversions.h" #include "base/synchronization/lock.h" +#include "ui/base/resource/material_design/material_design_controller.h" #include "ui/base/resource/resource_handle.h" #include "ui/gfx/image/image.h" @@ -48,6 +49,20 @@ base::FilePath GetResourcesPakFilePath(NSString* name, NSString* mac_locale) { } // namespace void ResourceBundle::LoadCommonResources() { + // The material design data packs contain some of the same asset IDs as in + // the non-material design data packs. Add these to the ResourceBundle + // first so that they are searched first when a request for an asset is + // made. + if (MaterialDesignController::IsModeMaterial()) { + AddMaterialDesignDataPackFromPath( + GetResourcesPakFilePath(@"chrome_material_100_percent", nil), + SCALE_FACTOR_100P); + + AddOptionalMaterialDesignDataPackFromPath( + GetResourcesPakFilePath(@"chrome_material_200_percent", nil), + SCALE_FACTOR_200P); + } + AddDataPackFromPath(GetResourcesPakFilePath(@"chrome_100_percent", nil), SCALE_FACTOR_100P); @@ -111,6 +126,8 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { if (delegate_) image = delegate_->GetNativeImageNamed(resource_id, rtl); + bool found_in_a_material_design_pack = false; + if (image.IsEmpty()) { base::scoped_nsobject<NSImage> ns_image; for (size_t i = 0; i < data_packs_.size(); ++i) { @@ -119,6 +136,18 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { if (!data.get()) continue; + // This loop adds the image resource from each available pack, if it's + // present. When Material Design packs are available, however, their + // images are meant to override the same image in the standard packs. The + // Material Design packs exist at the start of the data_packs_ vector, + // so make a note that the image was pulled from a Material Design pack, + // and ignore the same image in the standard packs. + if (found_in_a_material_design_pack) { + break; + } + found_in_a_material_design_pack = + data_packs_[i]->HasOnlyMaterialDesignAssets(); + base::scoped_nsobject<NSData> ns_data( [[NSData alloc] initWithBytes:data->front() length:data->size()]); if (!ns_image.get()) { diff --git a/chromium/ui/base/resource/resource_bundle_mac_unittest.mm b/chromium/ui/base/resource/resource_bundle_mac_unittest.mm new file mode 100644 index 00000000000..c52f6c3da84 --- /dev/null +++ b/chromium/ui/base/resource/resource_bundle_mac_unittest.mm @@ -0,0 +1,205 @@ +// Copyright 2015 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/base/resource/resource_bundle.h" + +#import <AppKit/AppKit.h> +#include <stddef.h> +#include <stdint.h> + +#include "base/base_paths.h" +#include "base/big_endian.h" +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/files/scoped_temp_dir.h" +#include "base/logging.h" +#include "base/macros.h" +#include "base/memory/ref_counted_memory.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/resource/data_pack.h" +#include "ui/gfx/codec/png_codec.h" +#include "ui/gfx/image/image_skia.h" +#include "ui/resources/grit/ui_resources.h" +#include "ui/strings/grit/app_locale_settings.h" + +namespace ui { + +extern const char kEmptyPakContents[]; +extern const size_t kEmptyPakSize; + +namespace { + +const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; +const size_t kPngChunkMetadataSize = 12; +const unsigned char kPngIHDRChunkType[4] = { 'I', 'H', 'D', 'R' }; + +// Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. +void AddCustomChunk(const base::StringPiece& custom_chunk, + std::vector<unsigned char>* bitmap_data) { + EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); + EXPECT_TRUE(std::equal( + bitmap_data->begin(), + bitmap_data->begin() + arraysize(kPngMagic), + kPngMagic)); + std::vector<unsigned char>::iterator ihdr_start = + bitmap_data->begin() + arraysize(kPngMagic); + char ihdr_length_data[sizeof(uint32_t)]; + for (size_t i = 0; i < sizeof(uint32_t); ++i) + ihdr_length_data[i] = *(ihdr_start + i); + uint32_t ihdr_chunk_length = 0; + base::ReadBigEndian(reinterpret_cast<char*>(ihdr_length_data), + &ihdr_chunk_length); + EXPECT_TRUE( + std::equal(ihdr_start + sizeof(uint32_t), + ihdr_start + sizeof(uint32_t) + sizeof(kPngIHDRChunkType), + kPngIHDRChunkType)); + + bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, + custom_chunk.begin(), custom_chunk.end()); +} + +// Creates datapack at |path| with a single bitmap at resource ID 3 +// which is |edge_size|x|edge_size| pixels. +// If |custom_chunk| is non empty, adds it after the IHDR chunk +// in the encoded bitmap data. +void CreateDataPackWithSingleBitmap(const base::FilePath& path, + int edge_size, + const base::StringPiece& custom_chunk) { + SkBitmap bitmap; + bitmap.allocN32Pixels(edge_size, edge_size); + bitmap.eraseColor(SK_ColorWHITE); + std::vector<unsigned char> bitmap_data; + EXPECT_TRUE(gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &bitmap_data)); + + if (custom_chunk.size() > 0) + AddCustomChunk(custom_chunk, &bitmap_data); + + std::map<uint16_t, base::StringPiece> resources; + resources[3u] = base::StringPiece( + reinterpret_cast<const char*>(&bitmap_data[0]), bitmap_data.size()); + DataPack::WritePack(path, resources, ui::DataPack::BINARY); +} + +} // namespace + +class ResourceBundleMacImageTest : public testing::Test { + public: + ResourceBundleMacImageTest() : resource_bundle_(NULL) {} + + ~ResourceBundleMacImageTest() override {} + + void SetUp() override { + // Create a temporary directory to write test resource bundles to. + ASSERT_TRUE(dir_.CreateUniqueTempDir()); + } + + // Overridden from testing::Test: + void TearDown() override { delete resource_bundle_; } + + // Returns new ResoureBundle with the specified |delegate|. The + // ResourceBundleTest class manages the lifetime of the returned + // ResourceBundle. + ResourceBundle* CreateResourceBundle(ResourceBundle::Delegate* delegate) { + DCHECK(!resource_bundle_); + + resource_bundle_ = new ResourceBundle(delegate); + return resource_bundle_; + } + + // Returns resource bundle which uses an empty data pak for locale data. + ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { + // Write an empty data pak for locale data. + const base::FilePath& locale_path = dir_path().Append( + FILE_PATH_LITERAL("locale.pak")); + EXPECT_EQ(base::WriteFile(locale_path, kEmptyPakContents, kEmptyPakSize), + static_cast<int>(kEmptyPakSize)); + + ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); + + // Load the empty locale data pak. + resource_bundle->LoadTestResources(base::FilePath(), locale_path); + return resource_bundle; + } + + // Returns the path of temporary directory to write test data packs into. + const base::FilePath& dir_path() { return dir_.path(); } + + // Returns the number of DataPacks managed by |resource_bundle| which are + // flagged as containing only material design resources. + size_t NumberOfMaterialDesignDataPacksInResourceBundle( + ResourceBundle* resource_bundle) { + DCHECK(resource_bundle); + size_t num_material_packs = 0; + for (size_t i = 0; i < resource_bundle->data_packs_.size(); i++) { + if (resource_bundle->data_packs_[i]->HasOnlyMaterialDesignAssets()) + num_material_packs++; + } + + return num_material_packs; + } + +protected: + ResourceBundle* resource_bundle_; + + private: + scoped_ptr<DataPack> locale_pack_; + base::ScopedTempDir dir_; + + DISALLOW_COPY_AND_ASSIGN(ResourceBundleMacImageTest); +}; + +// Verifies that ResourceBundle searches the Material Design data pack before +// the default data pack, and that the returned image contains only the +// representation from the Material Design pack. +TEST_F(ResourceBundleMacImageTest, CheckImageFromMaterialDesign) { + // Create two .pak files, each containing a single image with the + // same asset ID but different sizes (note that the images must be + // different sizes in this test in order to correctly determine + // from which data pack the asset was pulled). Note also that the value + // of |material_size| was chosen to be divisible by 3, since iOS may + // use this scale factor. + const int default_size = 10; + const int material_size = 48; + ASSERT_NE(default_size, material_size); + base::FilePath default_path = dir_path().AppendASCII("default.pak"); + base::FilePath material_path = dir_path().AppendASCII("material.pak"); + CreateDataPackWithSingleBitmap(default_path, + default_size, + base::StringPiece()); + CreateDataPackWithSingleBitmap(material_path, + material_size, + base::StringPiece()); + + ScaleFactor scale_factor = SCALE_FACTOR_100P; + ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); + + // Load the 'material' data pack into ResourceBundle first. + resource_bundle->AddMaterialDesignDataPackFromPath(material_path, + scale_factor); + resource_bundle->AddDataPackFromPath(default_path, scale_factor); + + // Confirm that there are two data packs available. + const unsigned int data_packs_size = resource_bundle->data_packs_.size(); + const unsigned int expected_size = 2; + EXPECT_EQ(expected_size, data_packs_size); + + const size_t md_data_pack_count = + NumberOfMaterialDesignDataPacksInResourceBundle(resource_bundle); + const size_t expected_pack_count = 1; + EXPECT_EQ(expected_pack_count, md_data_pack_count); + + // Normally with two packs containing the same image, GetNativeImageNamed() + // returns an NSImage that contains both representations. With the Material + // Design pack, any images it contains should override the ones in the default + // pack, so if both packs contain the same image, the returned NSImage should + // contain just a single representation. + NSImage* icon = resource_bundle->GetNativeImageNamed(3).ToNSImage(); + const unsigned long representations_count = [[icon representations] count]; + const unsigned long expected_count = 1; + EXPECT_EQ(expected_count, representations_count); +} + +} // namespace ui diff --git a/chromium/ui/base/resource/resource_bundle_unittest.cc b/chromium/ui/base/resource/resource_bundle_unittest.cc index a1d13772e1c..eac9ef37306 100644 --- a/chromium/ui/base/resource/resource_bundle_unittest.cc +++ b/chromium/ui/base/resource/resource_bundle_unittest.cc @@ -4,14 +4,19 @@ #include "ui/base/resource/resource_bundle.h" +#include <stddef.h> +#include <stdint.h> + #include "base/base_paths.h" #include "base/big_endian.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/strings/utf_string_conversions.h" +#include "build/build_config.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -105,16 +110,16 @@ void AddCustomChunk(const base::StringPiece& custom_chunk, kPngMagic)); std::vector<unsigned char>::iterator ihdr_start = bitmap_data->begin() + arraysize(kPngMagic); - char ihdr_length_data[sizeof(uint32)]; - for (size_t i = 0; i < sizeof(uint32); ++i) + char ihdr_length_data[sizeof(uint32_t)]; + for (size_t i = 0; i < sizeof(uint32_t); ++i) ihdr_length_data[i] = *(ihdr_start + i); - uint32 ihdr_chunk_length = 0; + uint32_t ihdr_chunk_length = 0; base::ReadBigEndian(reinterpret_cast<char*>(ihdr_length_data), &ihdr_chunk_length); - EXPECT_TRUE(std::equal( - ihdr_start + sizeof(uint32), - ihdr_start + sizeof(uint32) + sizeof(kPngIHDRChunkType), - kPngIHDRChunkType)); + EXPECT_TRUE( + std::equal(ihdr_start + sizeof(uint32_t), + ihdr_start + sizeof(uint32_t) + sizeof(kPngIHDRChunkType), + kPngIHDRChunkType)); bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, custom_chunk.begin(), custom_chunk.end()); @@ -136,7 +141,7 @@ void CreateDataPackWithSingleBitmap(const base::FilePath& path, if (custom_chunk.size() > 0) AddCustomChunk(custom_chunk, &bitmap_data); - std::map<uint16, base::StringPiece> resources; + std::map<uint16_t, base::StringPiece> resources; resources[3u] = base::StringPiece( reinterpret_cast<const char*>(&bitmap_data[0]), bitmap_data.size()); DataPack::WritePack(path, resources, ui::DataPack::BINARY); @@ -516,7 +521,7 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) { // via ResourceBundle::GetImageNamed(). TEST_F(ResourceBundleImageTest, GetImageNamed) { #if defined(OS_WIN) - gfx::InitDeviceScaleFactor(2.0); + gfx::SetDefaultDeviceScaleFactor(2.0); #endif std::vector<ScaleFactor> supported_factors; supported_factors.push_back(SCALE_FACTOR_100P); diff --git a/chromium/ui/base/resource/resource_bundle_win.h b/chromium/ui/base/resource/resource_bundle_win.h index 811464e1304..92590eaff97 100644 --- a/chromium/ui/base/resource/resource_bundle_win.h +++ b/chromium/ui/base/resource/resource_bundle_win.h @@ -9,7 +9,6 @@ #include <windows.h> -#include "base/basictypes.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/resource/resource_data_dll_win.cc b/chromium/ui/base/resource/resource_data_dll_win.cc index 1b8ff45f193..4cf32666f3f 100644 --- a/chromium/ui/base/resource/resource_data_dll_win.cc +++ b/chromium/ui/base/resource/resource_data_dll_win.cc @@ -4,6 +4,8 @@ #include "ui/base/resource/resource_data_dll_win.h" +#include <stddef.h> + #include "base/logging.h" #include "base/memory/ref_counted_memory.h" #include "base/win/resource_util.h" @@ -17,7 +19,7 @@ ResourceDataDLL::ResourceDataDLL(HINSTANCE module) : module_(module) { ResourceDataDLL::~ResourceDataDLL() { } -bool ResourceDataDLL::HasResource(uint16 resource_id) const { +bool ResourceDataDLL::HasResource(uint16_t resource_id) const { void* data_ptr; size_t data_size; return base::win::GetDataResourceFromModule(module_, @@ -26,7 +28,7 @@ bool ResourceDataDLL::HasResource(uint16 resource_id) const { &data_size); } -bool ResourceDataDLL::GetStringPiece(uint16 resource_id, +bool ResourceDataDLL::GetStringPiece(uint16_t resource_id, base::StringPiece* data) const { DCHECK(data); void* data_ptr; @@ -42,7 +44,7 @@ bool ResourceDataDLL::GetStringPiece(uint16 resource_id, } base::RefCountedStaticMemory* ResourceDataDLL::GetStaticMemory( - uint16 resource_id) const { + uint16_t resource_id) const { void* data_ptr; size_t data_size; if (base::win::GetDataResourceFromModule(module_, resource_id, &data_ptr, diff --git a/chromium/ui/base/resource/resource_data_dll_win.h b/chromium/ui/base/resource/resource_data_dll_win.h index 1ad1f9b927f..b7f60188d01 100644 --- a/chromium/ui/base/resource/resource_data_dll_win.h +++ b/chromium/ui/base/resource/resource_data_dll_win.h @@ -6,8 +6,10 @@ #define UI_BASE_RESOURCE_RESOURCE_DATA_DLL_WIN_H_ #include <windows.h> +#include <stdint.h> #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/resource/resource_handle.h" namespace ui { @@ -18,11 +20,11 @@ class ResourceDataDLL : public ResourceHandle { ~ResourceDataDLL() override; // ResourceHandle implementation: - bool HasResource(uint16 resource_id) const override; - bool GetStringPiece(uint16 resource_id, + bool HasResource(uint16_t resource_id) const override; + bool GetStringPiece(uint16_t resource_id, base::StringPiece* data) const override; base::RefCountedStaticMemory* GetStaticMemory( - uint16 resource_id) const override; + uint16_t resource_id) const override; TextEncodingType GetTextEncodingType() const override; ScaleFactor GetScaleFactor() const override; bool HasOnlyMaterialDesignAssets() const override; diff --git a/chromium/ui/base/resource/resource_handle.h b/chromium/ui/base/resource/resource_handle.h index 47958343760..138c739134c 100644 --- a/chromium/ui/base/resource/resource_handle.h +++ b/chromium/ui/base/resource/resource_handle.h @@ -5,7 +5,8 @@ #ifndef UI_BASE_RESOURCE_RESOURCE_HANDLE_H_ #define UI_BASE_RESOURCE_RESOURCE_HANDLE_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "base/strings/string_piece.h" #include "ui/base/layout.h" #include "ui/base/ui_base_export.h" @@ -28,18 +29,18 @@ class UI_BASE_EXPORT ResourceHandle { virtual ~ResourceHandle() {} // Returns true if the DataPack contains a resource with id |resource_id|. - virtual bool HasResource(uint16 resource_id) const = 0; + virtual bool HasResource(uint16_t resource_id) const = 0; // Get resource by id |resource_id|, filling in |data|. // The data is owned by the DataPack object and should not be modified. // Returns false if the resource id isn't found. - virtual bool GetStringPiece(uint16 resource_id, + virtual bool GetStringPiece(uint16_t resource_id, base::StringPiece* data) const = 0; // Like GetStringPiece(), but returns a reference to memory. // Caller owns the returned object. virtual base::RefCountedStaticMemory* GetStaticMemory( - uint16 resource_id) const = 0; + uint16_t resource_id) const = 0; // Get the encoding type of text resources. virtual TextEncodingType GetTextEncodingType() const = 0; diff --git a/chromium/ui/base/template_expressions.cc b/chromium/ui/base/template_expressions.cc index 43cfa53bc02..1d63e0c34ea 100644 --- a/chromium/ui/base/template_expressions.cc +++ b/chromium/ui/base/template_expressions.cc @@ -4,6 +4,8 @@ #include "ui/base/template_expressions.h" +#include <stddef.h> + #include "base/logging.h" namespace ui { @@ -17,7 +19,8 @@ std::string ReplaceTemplateExpressions( substitutions.size() * kValueLengthGuess); base::StringPiece::const_iterator i = format_string.begin(); while (i < format_string.end()) { - if (*i == '$' && i + 1 < format_string.end() && i[1] == '{') { + if (*i == '$' && i + 2 < format_string.end() && i[1] == '{' && + i[2] != '}') { size_t key_start = i + strlen("${") - format_string.begin(); size_t key_length = format_string.find('}', key_start); if (key_length == base::StringPiece::npos) diff --git a/chromium/ui/base/template_expressions_unittest.cc b/chromium/ui/base/template_expressions_unittest.cc index f5c363144ff..b56a5e7424c 100644 --- a/chromium/ui/base/template_expressions_unittest.cc +++ b/chromium/ui/base/template_expressions_unittest.cc @@ -12,25 +12,24 @@ TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) { std::map<base::StringPiece, std::string> substitutions; substitutions["test"] = "word"; substitutions["5"] = "number"; - substitutions[""] = "blank"; - EXPECT_EQ(ReplaceTemplateExpressions("${}", substitutions), "blank"); - EXPECT_EQ(ReplaceTemplateExpressions("", substitutions), ""); - EXPECT_EQ(ReplaceTemplateExpressions("${test}", substitutions), "word"); - EXPECT_EQ(ReplaceTemplateExpressions("${5} ", substitutions), "number "); + EXPECT_EQ("${}", ReplaceTemplateExpressions("${}", substitutions)); + EXPECT_EQ("", ReplaceTemplateExpressions("", substitutions)); + EXPECT_EQ("word", ReplaceTemplateExpressions("${test}", substitutions)); + EXPECT_EQ("number ", ReplaceTemplateExpressions("${5} ", substitutions)); EXPECT_EQ( - ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions), - "multiple: word, number."); + "multiple: word, number.", + ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions)); } TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) { std::map<base::StringPiece, std::string> substitutions; substitutions["a"] = "x"; - EXPECT_EQ(ReplaceTemplateExpressions("$ $$ $$$", substitutions), "$ $$ $$$"); - EXPECT_EQ(ReplaceTemplateExpressions("$${a}", substitutions), "$x"); - EXPECT_EQ(ReplaceTemplateExpressions("$$${a}", substitutions), "$$x"); - EXPECT_EQ(ReplaceTemplateExpressions("$12", substitutions), "$12"); + EXPECT_EQ("$ $$ $$$", ReplaceTemplateExpressions("$ $$ $$$", substitutions)); + EXPECT_EQ("$x", ReplaceTemplateExpressions("$${a}", substitutions)); + EXPECT_EQ("$$x", ReplaceTemplateExpressions("$$${a}", substitutions)); + EXPECT_EQ("$12", ReplaceTemplateExpressions("$12", substitutions)); } } // namespace ui diff --git a/chromium/ui/base/text/bytes_formatting.cc b/chromium/ui/base/text/bytes_formatting.cc index 7f98c6b6e53..aff188c2cb8 100644 --- a/chromium/ui/base/text/bytes_formatting.cc +++ b/chromium/ui/base/text/bytes_formatting.cc @@ -6,6 +6,7 @@ #include "base/i18n/number_formatting.h" #include "base/logging.h" +#include "base/macros.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "ui/base/l10n/l10n_util.h" @@ -34,7 +35,7 @@ const int kSpeedStrings[] = { IDS_APP_PEBIBYTES_PER_SECOND }; -base::string16 FormatBytesInternal(int64 bytes, +base::string16 FormatBytesInternal(int64_t bytes, DataUnits units, bool show_units, const int* const suffix) { @@ -63,17 +64,17 @@ base::string16 FormatBytesInternal(int64 bytes, } // namespace -DataUnits GetByteDisplayUnits(int64 bytes) { +DataUnits GetByteDisplayUnits(int64_t bytes) { // The byte thresholds at which we display amounts. A byte count is displayed // in unit U when kUnitThresholds[U] <= bytes < kUnitThresholds[U+1]. // This must match the DataUnits enum. - static const int64 kUnitThresholds[] = { - 0, // DATA_UNITS_BYTE, - 3 * (1LL << 10), // DATA_UNITS_KIBIBYTE, - 2 * (1LL << 20), // DATA_UNITS_MEBIBYTE, - 1LL << 30, // DATA_UNITS_GIBIBYTE, - 1LL << 40, // DATA_UNITS_TEBIBYTE, - 1LL << 50 // DATA_UNITS_PEBIBYTE, + static const int64_t kUnitThresholds[] = { + 0, // DATA_UNITS_BYTE, + 3 * (1LL << 10), // DATA_UNITS_KIBIBYTE, + 2 * (1LL << 20), // DATA_UNITS_MEBIBYTE, + 1LL << 30, // DATA_UNITS_GIBIBYTE, + 1LL << 40, // DATA_UNITS_TEBIBYTE, + 1LL << 50 // DATA_UNITS_PEBIBYTE, }; if (bytes < 0) { @@ -91,23 +92,23 @@ DataUnits GetByteDisplayUnits(int64 bytes) { return DataUnits(unit_index); } -base::string16 FormatBytesWithUnits(int64 bytes, +base::string16 FormatBytesWithUnits(int64_t bytes, DataUnits units, bool show_units) { return FormatBytesInternal(bytes, units, show_units, kByteStrings); } -base::string16 FormatSpeedWithUnits(int64 bytes, +base::string16 FormatSpeedWithUnits(int64_t bytes, DataUnits units, bool show_units) { return FormatBytesInternal(bytes, units, show_units, kSpeedStrings); } -base::string16 FormatBytes(int64 bytes) { +base::string16 FormatBytes(int64_t bytes) { return FormatBytesWithUnits(bytes, GetByteDisplayUnits(bytes), true); } -base::string16 FormatSpeed(int64 bytes) { +base::string16 FormatSpeed(int64_t bytes) { return FormatSpeedWithUnits(bytes, GetByteDisplayUnits(bytes), true); } diff --git a/chromium/ui/base/text/bytes_formatting.h b/chromium/ui/base/text/bytes_formatting.h index 46de51c7549..7cb6e45ce62 100644 --- a/chromium/ui/base/text/bytes_formatting.h +++ b/chromium/ui/base/text/bytes_formatting.h @@ -5,7 +5,8 @@ #ifndef UI_BASE_TEXT_BYTES_FORMATTING_H_ #define UI_BASE_TEXT_BYTES_FORMATTING_H_ -#include "base/basictypes.h" +#include <stdint.h> + #include "base/strings/string16.h" #include "ui/base/ui_base_export.h" @@ -16,12 +17,12 @@ namespace ui { // Simple call to return a byte quantity as a string in human-readable format. // Ex: FormatBytes(512) => "512 B" // Ex: FormatBytes(101479) => "99.1 kB" -UI_BASE_EXPORT base::string16 FormatBytes(int64 bytes); +UI_BASE_EXPORT base::string16 FormatBytes(int64_t bytes); // Simple call to return a speed as a string in human-readable format. // Ex: FormatSpeed(512) => "512 B/s" // Ex: FormatSpeed(101479) => "99.1 kB/s" -UI_BASE_EXPORT base::string16 FormatSpeed(int64 bytes); +UI_BASE_EXPORT base::string16 FormatSpeed(int64_t bytes); // Less-Simple API ------------------------------------------------------------- @@ -37,20 +38,20 @@ enum DataUnits { // Return the unit type that is appropriate for displaying the amount of bytes // passed in. Most of the time, an explicit call to this isn't necessary; just // use FormatBytes()/FormatSpeed() above. -UI_BASE_EXPORT DataUnits GetByteDisplayUnits(int64 bytes); +UI_BASE_EXPORT DataUnits GetByteDisplayUnits(int64_t bytes); // Return a byte quantity as a string in human-readable format with an optional // unit suffix. Specify in the |units| argument the units to be used. // Ex: FormatBytes(512, DATA_UNITS_KIBIBYTE, true) => "0.5 kB" // Ex: FormatBytes(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1" -UI_BASE_EXPORT base::string16 FormatBytesWithUnits(int64 bytes, +UI_BASE_EXPORT base::string16 FormatBytesWithUnits(int64_t bytes, DataUnits units, bool show_units); // As above, but with "/s" units for speed values. // Ex: FormatSpeed(512, DATA_UNITS_KIBIBYTE, true) => "0.5 kB/s" // Ex: FormatSpeed(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1" -base::string16 FormatSpeedWithUnits(int64 bytes, +base::string16 FormatSpeedWithUnits(int64_t bytes, DataUnits units, bool show_units); diff --git a/chromium/ui/base/text/bytes_formatting_unittest.cc b/chromium/ui/base/text/bytes_formatting_unittest.cc index 308996c8f3c..b2c2a410a5c 100644 --- a/chromium/ui/base/text/bytes_formatting_unittest.cc +++ b/chromium/ui/base/text/bytes_formatting_unittest.cc @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <stddef.h> +#include <stdint.h> + +#include "base/macros.h" #include "base/strings/utf_string_conversions.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/text/bytes_formatting.h" @@ -10,7 +14,7 @@ namespace ui { TEST(BytesFormattingTest, GetByteDisplayUnits) { static const struct { - int64 bytes; + int64_t bytes; DataUnits expected; } cases[] = { {0, DATA_UNITS_BYTE}, @@ -31,7 +35,7 @@ TEST(BytesFormattingTest, GetByteDisplayUnits) { TEST(BytesFormattingTest, FormatBytes) { static const struct { - int64 bytes; + int64_t bytes; DataUnits units; const char* expected; const char* expected_with_units; diff --git a/chromium/ui/base/theme_provider.h b/chromium/ui/base/theme_provider.h index eeab83d796c..fa86e43ede0 100644 --- a/chromium/ui/base/theme_provider.h +++ b/chromium/ui/base/theme_provider.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_THEME_PROVIDER_H_ #define UI_BASE_THEME_PROVIDER_H_ -#include "base/basictypes.h" +#include "build/build_config.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/base/layout.h" #include "ui/base/ui_base_export.h" @@ -47,10 +47,6 @@ class UI_BASE_EXPORT ThemeProvider { public: virtual ~ThemeProvider(); - // Whether we're using the system theme (which may or may not be the - // same as the default theme). - virtual bool UsingSystemTheme() const = 0; - // Get the image specified by |id|. An implementation of ThemeProvider should // have its own source of ids (e.g. an enum, or external resource bundle). virtual gfx::ImageSkia* GetImageSkiaNamed(int id) const = 0; @@ -78,6 +74,12 @@ class UI_BASE_EXPORT ThemeProvider { ui::ScaleFactor scale_factor) const = 0; #if defined(OS_MACOSX) + // Whether we're using the system theme (which may or may not be the + // same as the default theme). + // TODO(estade): this should probably just be part of ThemeService and not + // ThemeProvider, but it's used in many places on OSX. + virtual bool UsingSystemTheme() const = 0; + // Gets the NSImage with the specified |id|. virtual NSImage* GetNSImageNamed(int id) const = 0; diff --git a/chromium/ui/base/touch/selection_bound_unittest.cc b/chromium/ui/base/touch/selection_bound_unittest.cc index 7a8e65160c1..95ba5fbc3f2 100644 --- a/chromium/ui/base/touch/selection_bound_unittest.cc +++ b/chromium/ui/base/touch/selection_bound_unittest.cc @@ -12,8 +12,8 @@ namespace ui { TEST(SelectionBoundTest, RectBetweenSelectionBounds) { SelectionBound b1, b2; // Simple case of aligned vertical bounds of equal height - b1.SetEdge(gfx::Point(0, 20), gfx::Point(0, 25)); - b2.SetEdge(gfx::Point(110, 20), gfx::Point(110, 25)); + b1.SetEdge(gfx::PointF(0.f, 20.f), gfx::PointF(0.f, 25.f)); + b2.SetEdge(gfx::PointF(110.f, 20.f), gfx::PointF(110.f, 25.f)); gfx::Rect expected_rect( b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), @@ -23,8 +23,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); // Parallel vertical bounds of different heights - b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 25)); - b2.SetEdge(gfx::Point(110, 0), gfx::Point(110, 35)); + b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 25.f)); + b2.SetEdge(gfx::PointF(110.f, 0.f), gfx::PointF(110.f, 35.f)); expected_rect = gfx::Rect( b1.edge_top_rounded().x(), b2.edge_top_rounded().y(), @@ -33,8 +33,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); - b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); - b2.SetEdge(gfx::Point(110, 25), gfx::Point(110, 45)); + b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); + b2.SetEdge(gfx::PointF(110.f, 25.f), gfx::PointF(110.f, 45.f)); expected_rect = gfx::Rect( b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), @@ -43,8 +43,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b1, b2)); EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); - b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); - b2.SetEdge(gfx::Point(110, 40), gfx::Point(110, 60)); + b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); + b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(110.f, 60.f)); expected_rect = gfx::Rect( b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), @@ -54,8 +54,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); // Overlapping vertical bounds - b1.SetEdge(gfx::Point(10, 20), gfx::Point(10, 30)); - b2.SetEdge(gfx::Point(10, 25), gfx::Point(10, 40)); + b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(10.f, 30.f)); + b2.SetEdge(gfx::PointF(10.f, 25.f), gfx::PointF(10.f, 40.f)); expected_rect = gfx::Rect( b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), @@ -65,8 +65,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); // Non-vertical bounds: "\ \" - b1.SetEdge(gfx::Point(10, 20), gfx::Point(20, 30)); - b2.SetEdge(gfx::Point(110, 40), gfx::Point(120, 60)); + b1.SetEdge(gfx::PointF(10.f, 20.f), gfx::PointF(20.f, 30.f)); + b2.SetEdge(gfx::PointF(110.f, 40.f), gfx::PointF(120.f, 60.f)); expected_rect = gfx::Rect( b1.edge_top_rounded().x(), b1.edge_top_rounded().y(), @@ -76,8 +76,8 @@ TEST(SelectionBoundTest, RectBetweenSelectionBounds) { EXPECT_EQ(expected_rect, RectBetweenSelectionBounds(b2, b1)); // Non-vertical bounds: "/ \" - b1.SetEdge(gfx::Point(20, 30), gfx::Point(0, 40)); - b2.SetEdge(gfx::Point(110, 30), gfx::Point(120, 40)); + b1.SetEdge(gfx::PointF(20.f, 30.f), gfx::PointF(0.f, 40.f)); + b2.SetEdge(gfx::PointF(110.f, 30.f), gfx::PointF(120.f, 40.f)); expected_rect = gfx::Rect( b1.edge_bottom_rounded().x(), b1.edge_top_rounded().y(), diff --git a/chromium/ui/base/touch/touch_device.cc b/chromium/ui/base/touch/touch_device.cc index 8aa63404d87..5b02be22965 100644 --- a/chromium/ui/base/touch/touch_device.cc +++ b/chromium/ui/base/touch/touch_device.cc @@ -8,8 +8,8 @@ namespace ui { // Platforms supporting touch link in an alternate implementation of this // method. -bool IsTouchDevicePresent() { - return false; +TouchScreensAvailability GetTouchScreensAvailability() { + return TouchScreensAvailability::NONE; } int MaxTouchPoints() { diff --git a/chromium/ui/base/touch/touch_device.h b/chromium/ui/base/touch/touch_device.h index d87b645996b..544a5edee7e 100644 --- a/chromium/ui/base/touch/touch_device.h +++ b/chromium/ui/base/touch/touch_device.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_TOUCH_TOUCH_DEVICE_H_ #define UI_BASE_TOUCH_TOUCH_DEVICE_H_ +#include "build/build_config.h" #include "ui/base/ui_base_export.h" #if defined(OS_ANDROID) @@ -16,8 +17,13 @@ namespace ui { -// Returns true if a touch device is available. -UI_BASE_EXPORT bool IsTouchDevicePresent(); +enum class TouchScreensAvailability { + NONE, // No touch screens are present. + ENABLED, // Touch screens are present and enabled. + DISABLED, // Touch screens are present and disabled. +}; + +UI_BASE_EXPORT TouchScreensAvailability GetTouchScreensAvailability(); // Returns the maximum number of simultaneous touch contacts supported // by the device. In the case of devices with multiple digitizers (e.g. diff --git a/chromium/ui/base/touch/touch_device_android.cc b/chromium/ui/base/touch/touch_device_android.cc index 5754c65c005..dcd713db5b7 100644 --- a/chromium/ui/base/touch/touch_device_android.cc +++ b/chromium/ui/base/touch/touch_device_android.cc @@ -4,13 +4,14 @@ #include "ui/base/touch/touch_device.h" +#include "base/android/context_utils.h" #include "base/logging.h" #include "jni/TouchDevice_jni.h" namespace ui { -bool IsTouchDevicePresent() { - return true; +TouchScreensAvailability GetTouchScreensAvailability() { + return TouchScreensAvailability::ENABLED; } int MaxTouchPoints() { diff --git a/chromium/ui/base/touch/touch_device_ios.cc b/chromium/ui/base/touch/touch_device_ios.cc index 9f4c712e42b..18ffc7436d8 100644 --- a/chromium/ui/base/touch/touch_device_ios.cc +++ b/chromium/ui/base/touch/touch_device_ios.cc @@ -6,8 +6,8 @@ namespace ui { -bool IsTouchDevicePresent() { - return true; +TouchScreensAvailability GetTouchScreensAvailability() { + return TouchScreensAvailability::ENABLED; } } // namespace ui diff --git a/chromium/ui/base/touch/touch_device_linux.cc b/chromium/ui/base/touch/touch_device_linux.cc index 2e29c1d8d54..0bc89706c18 100644 --- a/chromium/ui/base/touch/touch_device_linux.cc +++ b/chromium/ui/base/touch/touch_device_linux.cc @@ -9,8 +9,21 @@ namespace ui { +namespace { + bool IsTouchDevicePresent() { - return ui::DeviceDataManager::GetInstance()->touchscreen_devices().size() > 0; + return !DeviceDataManager::GetInstance()->touchscreen_devices().empty(); +} + +} // namespace + +TouchScreensAvailability GetTouchScreensAvailability() { + if (!IsTouchDevicePresent()) + return TouchScreensAvailability::NONE; + + return DeviceDataManager::GetInstance()->AreTouchscreensEnabled() ? + TouchScreensAvailability::ENABLED : + TouchScreensAvailability::DISABLED; } int MaxTouchPoints() { diff --git a/chromium/ui/base/touch/touch_device_win.cc b/chromium/ui/base/touch/touch_device_win.cc index 04434fc16a9..26554862ef7 100644 --- a/chromium/ui/base/touch/touch_device_win.cc +++ b/chromium/ui/base/touch/touch_device_win.cc @@ -9,12 +9,23 @@ namespace ui { +namespace { + bool IsTouchDevicePresent() { int value = GetSystemMetrics(SM_DIGITIZER); return (value & NID_READY) && ((value & NID_INTEGRATED_TOUCH) || (value & NID_EXTERNAL_TOUCH)); } +} // namespace + +TouchScreensAvailability GetTouchScreensAvailability() { + if (!IsTouchDevicePresent()) + return TouchScreensAvailability::NONE; + + return TouchScreensAvailability::ENABLED; +} + int MaxTouchPoints() { if (!IsTouchDevicePresent()) return 0; diff --git a/chromium/ui/base/touch/touch_enabled.cc b/chromium/ui/base/touch/touch_enabled.cc index 89d3eac9fd4..4992f2ff627 100644 --- a/chromium/ui/base/touch/touch_enabled.cc +++ b/chromium/ui/base/touch/touch_enabled.cc @@ -1,32 +1,59 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2015 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/base/touch/touch_enabled.h" + #include "base/command_line.h" #include "base/logging.h" #include "ui/base/touch/touch_device.h" #include "ui/base/ui_base_switches.h" +#include "ui/events/base_event_utils.h" #include "ui/events/event_switches.h" namespace ui { -bool AreTouchEventsEnabled() { - const base::CommandLine& command_line = - *base::CommandLine::ForCurrentProcess(); +namespace { + +enum class TouchEventsStatus { + AUTO, + DISABLED, + ENABLED, +}; + +TouchEventsStatus ComputeTouchFlagStatus() { + auto* command_line = base::CommandLine::ForCurrentProcess(); const std::string touch_enabled_switch = - command_line.HasSwitch(switches::kTouchEvents) ? - command_line.GetSwitchValueASCII(switches::kTouchEvents) : - switches::kTouchEventsAuto; + command_line->HasSwitch(switches::kTouchEvents) ? + command_line->GetSwitchValueASCII(switches::kTouchEvents) : + switches::kTouchEventsAuto; if (touch_enabled_switch.empty() || - touch_enabled_switch == switches::kTouchEventsEnabled) - return true; + touch_enabled_switch == switches::kTouchEventsEnabled) { + return TouchEventsStatus::ENABLED; + } + if (touch_enabled_switch == switches::kTouchEventsAuto) - return IsTouchDevicePresent(); - if (touch_enabled_switch != switches::kTouchEventsDisabled) - LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch; - return false; + return TouchEventsStatus::AUTO; + + DLOG_IF(ERROR, touch_enabled_switch != switches::kTouchEventsDisabled) << + "Invalid --touch-events option: " << touch_enabled_switch; + return TouchEventsStatus::DISABLED; +} + +} // namespace + +bool AreTouchEventsEnabled() { + static TouchEventsStatus touch_flag_status = ComputeTouchFlagStatus(); + + // The #touch-events flag is used to force and simulate the presence or + // absence of touch devices. Only if the flag is set to AUTO, we need to check + // for the actual availability of touch devices. + if (touch_flag_status == TouchEventsStatus::AUTO) + return GetTouchScreensAvailability() == TouchScreensAvailability::ENABLED; + + return touch_flag_status == TouchEventsStatus::ENABLED; } } // namespace ui + diff --git a/chromium/ui/base/touch/touch_enabled.h b/chromium/ui/base/touch/touch_enabled.h index 88837d7856c..3d91c3a2ff0 100644 --- a/chromium/ui/base/touch/touch_enabled.h +++ b/chromium/ui/base/touch/touch_enabled.h @@ -1,4 +1,4 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2015 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. diff --git a/chromium/ui/base/ui_base.gyp b/chromium/ui/base/ui_base.gyp index 487d2b3f927..565faed3fe6 100644 --- a/chromium/ui/base/ui_base.gyp +++ b/chromium/ui/base/ui_base.gyp @@ -198,6 +198,7 @@ 'hit_test.h', 'idle/idle.cc', 'idle/idle.h', + 'idle/idle_android.cc', 'idle/idle_chromeos.cc', 'idle/idle_linux.cc', 'idle/idle_mac.mm', @@ -431,7 +432,7 @@ '../../build/linux/system.gyp:glib', ], }], - ['desktop_linux == 1 or chromeos == 1', { + ['OS=="linux"', { 'conditions': [ ['toolkit_views==0 and use_aura==0', { # Note: because of gyp predence rules this has to be defined as @@ -584,8 +585,6 @@ 'default_theme_provider.cc', 'dragdrop/drag_utils.cc', 'dragdrop/drag_utils.h', - 'idle/idle.cc', - 'idle/idle.h', 'l10n/l10n_font_util.cc', 'models/button_menu_item_model.cc', 'models/dialog_model.cc', @@ -606,7 +605,10 @@ }], ['OS=="android" and use_aura==0', { 'sources!': [ - 'cursor/cursor_android.cc' + 'cursor/cursor_android.cc', + 'idle/idle.cc', + 'idle/idle.h', + 'idle/idle_android.cc', ], }], ['OS=="android" and use_aura==1', { diff --git a/chromium/ui/base/ui_base_paths.cc b/chromium/ui/base/ui_base_paths.cc index c0246f8b2b3..48aae4c1882 100644 --- a/chromium/ui/base/ui_base_paths.cc +++ b/chromium/ui/base/ui_base_paths.cc @@ -9,6 +9,7 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "base/path_service.h" +#include "build/build_config.h" #if defined(OS_ANDROID) #include "base/android/path_utils.h" diff --git a/chromium/ui/base/ui_base_switches.cc b/chromium/ui/base/ui_base_switches.cc index c09bbaf87ab..76609e1f4a4 100644 --- a/chromium/ui/base/ui_base_switches.cc +++ b/chromium/ui/base/ui_base_switches.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "build/build_config.h" #include "ui/base/ui_base_switches.h" namespace switches { @@ -19,6 +20,14 @@ const char kDisableRemoteCoreAnimation[] = "disable-remote-core-animation"; const char kShowMacOverlayBorders[] = "show-mac-overlay-borders"; #endif +#if defined(OS_WIN) +// Disables merging the key event (WM_KEY*) with the char event (WM_CHAR). +const char kDisableMergeKeyCharEvents[] = "disable-merge-key-char-events"; + +// Enables merging the key event (WM_KEY*) with the char event (WM_CHAR). +const char kEnableMergeKeyCharEvents[] = "enable-merge-key-char-events"; +#endif + // Disables use of DWM composition for top level windows. const char kDisableDwmComposition[] = "disable-dwm-composition"; @@ -31,9 +40,6 @@ const char kDisableTouchAdjustment[] = "disable-touch-adjustment"; // Disables touch event based drag and drop. const char kDisableTouchDragDrop[] = "disable-touch-drag-drop"; -// Disables controls that support touch base text editing. -const char kDisableTouchEditing[] = "disable-touch-editing"; - // Disables additional visual feedback to touch input. const char kDisableTouchFeedback[] = "disable-touch-feedback"; @@ -47,9 +53,6 @@ const char kEnableLinkDisambiguationPopup[] = // Enables touch event based drag and drop. const char kEnableTouchDragDrop[] = "enable-touch-drag-drop"; -// Enables controls that support touch base text editing. -const char kEnableTouchEditing[] = "enable-touch-editing"; - // The language file that we want to try to open. Of the form // language[-country] where language is the 2 letter code from ISO-639. const char kLang[] = "lang"; diff --git a/chromium/ui/base/ui_base_switches.h b/chromium/ui/base/ui_base_switches.h index 3af67583723..e0c5849e147 100644 --- a/chromium/ui/base/ui_base_switches.h +++ b/chromium/ui/base/ui_base_switches.h @@ -8,6 +8,7 @@ #define UI_BASE_UI_BASE_SWITCHES_H_ #include "base/compiler_specific.h" +#include "build/build_config.h" #include "ui/base/ui_base_export.h" namespace switches { @@ -18,16 +19,19 @@ UI_BASE_EXPORT extern const char kDisableRemoteCoreAnimation[]; UI_BASE_EXPORT extern const char kShowMacOverlayBorders[]; #endif +#if defined(OS_WIN) +UI_BASE_EXPORT extern const char kDisableMergeKeyCharEvents[]; +UI_BASE_EXPORT extern const char kEnableMergeKeyCharEvents[]; +#endif + UI_BASE_EXPORT extern const char kDisableDwmComposition[]; UI_BASE_EXPORT extern const char kDisableIconNtp[]; UI_BASE_EXPORT extern const char kDisableTouchAdjustment[]; UI_BASE_EXPORT extern const char kDisableTouchDragDrop[]; -UI_BASE_EXPORT extern const char kDisableTouchEditing[]; UI_BASE_EXPORT extern const char kDisableTouchFeedback[]; UI_BASE_EXPORT extern const char kEnableIconNtp[]; UI_BASE_EXPORT extern const char kEnableLinkDisambiguationPopup[]; UI_BASE_EXPORT extern const char kEnableTouchDragDrop[]; -UI_BASE_EXPORT extern const char kEnableTouchEditing[]; UI_BASE_EXPORT extern const char kLang[]; UI_BASE_EXPORT extern const char kMaterialDesignInkDropAnimationSpeed[]; UI_BASE_EXPORT extern const char kMaterialDesignInkDropAnimationSpeedFast[]; diff --git a/chromium/ui/base/ui_base_switches_util.cc b/chromium/ui/base/ui_base_switches_util.cc index e529a7c8d9e..0830b3b27d3 100644 --- a/chromium/ui/base/ui_base_switches_util.cc +++ b/chromium/ui/base/ui_base_switches_util.cc @@ -5,6 +5,7 @@ #include "ui/base/ui_base_switches_util.h" #include "base/command_line.h" +#include "build/build_config.h" #include "ui/base/ui_base_switches.h" namespace switches { @@ -31,16 +32,6 @@ bool IsTouchDragDropEnabled() { #endif } -bool IsTouchEditingEnabled() { -#if defined(USE_AURA) - return !base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableTouchEditing); -#else - return base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kEnableTouchEditing); -#endif -} - bool IsTouchFeedbackEnabled() { static bool touch_feedback_enabled = !base::CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chromium/ui/base/ui_base_switches_util.h b/chromium/ui/base/ui_base_switches_util.h index fe6c289f2b6..14ca97c6024 100644 --- a/chromium/ui/base/ui_base_switches_util.h +++ b/chromium/ui/base/ui_base_switches_util.h @@ -11,7 +11,6 @@ namespace switches { UI_BASE_EXPORT bool IsLinkDisambiguationPopupEnabled(); UI_BASE_EXPORT bool IsTouchDragDropEnabled(); -UI_BASE_EXPORT bool IsTouchEditingEnabled(); UI_BASE_EXPORT bool IsTouchFeedbackEnabled(); } // namespace switches diff --git a/chromium/ui/base/ui_base_tests.gyp b/chromium/ui/base/ui_base_tests.gyp index d47436b8e36..483b5ae6dec 100644 --- a/chromium/ui/base/ui_base_tests.gyp +++ b/chromium/ui/base/ui_base_tests.gyp @@ -44,6 +44,7 @@ 'resource/data_pack_literal.cc', 'resource/data_pack_unittest.cc', 'resource/resource_bundle_unittest.cc', + 'resource/resource_bundle_mac_unittest.mm', 'template_expressions_unittest.cc', 'test/run_all_unittests.cc', ], @@ -71,8 +72,8 @@ 'cocoa/tracking_area_unittest.mm', 'dragdrop/os_exchange_data_provider_aurax11_unittest.cc', 'ime/candidate_window_unittest.cc', + 'ime/composition_text_unittest.cc', 'ime/chromeos/character_composer_unittest.cc', - 'ime/chromeos/composition_text_chromeos_unittest.cc', 'ime/composition_text_util_pango_unittest.cc', 'ime/input_method_base_unittest.cc', 'ime/input_method_chromeos_unittest.cc', @@ -288,8 +289,29 @@ 'includes': [ '../../build/apk_test.gypi' ], }, ], + 'conditions': [ + ['test_isolation_mode != "noop"', + { + 'targets': [ + { + 'target_name': 'ui_base_unittests_apk_run', + 'type': 'none', + 'dependencies': [ + 'ui_base_unittests_apk', + ], + 'includes': [ + '../../build/isolate.gypi', + ], + 'sources': [ + 'ui_base_unittests_apk.isolate', + ], + }, + ], + }, + ], + ], }], - ['test_isolation_mode != "noop"', { + ['test_isolation_mode != "noop" and OS != "android"', { 'targets': [ { 'target_name': 'ui_base_unittests_run', diff --git a/chromium/ui/base/ui_base_unittests_apk.isolate b/chromium/ui/base/ui_base_unittests_apk.isolate new file mode 100644 index 00000000000..33fc4811634 --- /dev/null +++ b/chromium/ui/base/ui_base_unittests_apk.isolate @@ -0,0 +1,20 @@ +# Copyright 2015 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. +{ + 'includes': [ + '../../build/android/android.isolate', + 'ui_base_tests.isolate' + ], + 'variables': { + 'command': [ + '<(PRODUCT_DIR)/bin/run_ui_base_unittests', + ], + 'files': [ + '../../third_party/icu/icu.isolate', + '<(PRODUCT_DIR)/bin/run_ui_base_unittests', + '<(PRODUCT_DIR)/ui_base_unittests_apk/', + 'ui_base_tests.isolate', + ] + }, +} diff --git a/chromium/ui/base/user_activity/user_activity_detector.cc b/chromium/ui/base/user_activity/user_activity_detector.cc index 78812bc76b7..bffe4796c9e 100644 --- a/chromium/ui/base/user_activity/user_activity_detector.cc +++ b/chromium/ui/base/user_activity/user_activity_detector.cc @@ -7,6 +7,7 @@ #include "base/format_macros.h" #include "base/logging.h" #include "base/strings/stringprintf.h" +#include "build/build_config.h" #include "ui/base/user_activity/user_activity_observer.h" #include "ui/events/event_utils.h" #include "ui/events/platform/platform_event_source.h" diff --git a/chromium/ui/base/user_activity/user_activity_detector.h b/chromium/ui/base/user_activity/user_activity_detector.h index 4ec398f9ee3..a480bedd28e 100644 --- a/chromium/ui/base/user_activity/user_activity_detector.h +++ b/chromium/ui/base/user_activity/user_activity_detector.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ #define UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/observer_list.h" #include "base/time/time.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/user_activity/user_activity_detector_unittest.cc b/chromium/ui/base/user_activity/user_activity_detector_unittest.cc index 68d9056c851..baebd1d598f 100644 --- a/chromium/ui/base/user_activity/user_activity_detector_unittest.cc +++ b/chromium/ui/base/user_activity/user_activity_detector_unittest.cc @@ -5,6 +5,7 @@ #include "ui/base/user_activity/user_activity_detector.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/time/time.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/ui/base/user_activity/user_activity_observer.h b/chromium/ui/base/user_activity/user_activity_observer.h index 7990cb8765a..f6b98d210af 100644 --- a/chromium/ui/base/user_activity/user_activity_observer.h +++ b/chromium/ui/base/user_activity/user_activity_observer.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_USER_ACTIVITY_USER_ACTIVITY_OBSERVER_H_ #define UI_BASE_USER_ACTIVITY_USER_ACTIVITY_OBSERVER_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/view_prop.cc b/chromium/ui/base/view_prop.cc index cb585531ae0..2ff403e2e31 100644 --- a/chromium/ui/base/view_prop.cc +++ b/chromium/ui/base/view_prop.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/macros.h" #include "ui/base/view_prop.h" #include <set> diff --git a/chromium/ui/base/view_prop.h b/chromium/ui/base/view_prop.h index 3ce14ba5d95..c81e995b0ba 100644 --- a/chromium/ui/base/view_prop.h +++ b/chromium/ui/base/view_prop.h @@ -5,8 +5,9 @@ #ifndef UI_BASE_VIEW_PROP_H_ #define UI_BASE_VIEW_PROP_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "base/memory/ref_counted.h" +#include "build/build_config.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" diff --git a/chromium/ui/base/webui/web_ui_util.cc b/chromium/ui/base/webui/web_ui_util.cc index 6483f077b72..d9c1d76da66 100644 --- a/chromium/ui/base/webui/web_ui_util.cc +++ b/chromium/ui/base/webui/web_ui_util.cc @@ -13,6 +13,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/trace_event/trace_event.h" +#include "build/build_config.h" #include "net/base/escape.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" @@ -36,9 +37,11 @@ std::string GetBitmapDataUrl(const SkBitmap& bitmap) { "width", bitmap.width(), "height", bitmap.height()); std::vector<unsigned char> output; gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &output); - std::string str_url; - str_url.insert(str_url.end(), output.begin(), output.end()); + return GetPngDataUrl(output.data(), output.size()); +} +std::string GetPngDataUrl(const unsigned char* data, size_t size) { + std::string str_url(reinterpret_cast<const char*>(data), size); base::Base64Encode(str_url, &str_url); str_url.insert(0, "data:image/png;base64,"); return str_url; @@ -119,19 +122,30 @@ void SetLoadTimeDataDefaults(const std::string& app_locale, localized_strings->SetString("textdirection", GetTextDirection()); } -std::string GetWebUiCssTextDefaults() { +std::string GetWebUiCssTextDefaults(const std::string& css_template) { std::map<base::StringPiece, std::string> placeholders; placeholders["textDirection"] = GetTextDirection(); placeholders["fontFamily"] = GetFontFamily(); placeholders["fontSize"] = GetFontSize(); + return ui::ReplaceTemplateExpressions(css_template, placeholders); +} +std::string GetWebUiCssTextDefaults() { const ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); const std::string& css_template = resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS) .as_string(); + return GetWebUiCssTextDefaults(css_template); +} - return ui::ReplaceTemplateExpressions(css_template, placeholders); +std::string GetWebUiCssTextDefaultsMd() { + const ui::ResourceBundle& resource_bundle = + ui::ResourceBundle::GetSharedInstance(); + const std::string& css_template = + resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS_MD) + .as_string(); + return GetWebUiCssTextDefaults(css_template); } void AppendWebUiCssTextDefaults(std::string* html) { diff --git a/chromium/ui/base/webui/web_ui_util.h b/chromium/ui/base/webui/web_ui_util.h index 95f1856f34f..dc2483995fb 100644 --- a/chromium/ui/base/webui/web_ui_util.h +++ b/chromium/ui/base/webui/web_ui_util.h @@ -5,6 +5,8 @@ #ifndef UI_BASE_WEBUI_WEB_UI_UTIL_H_ #define UI_BASE_WEBUI_WEB_UI_UTIL_H_ +#include <stddef.h> + #include <string> #include "base/strings/string_piece.h" @@ -21,6 +23,10 @@ namespace webui { // so that it can be used in WebUI. UI_BASE_EXPORT std::string GetBitmapDataUrl(const SkBitmap& bitmap); +// Convenience routine to convert an in-memory PNG to a data url for WebUI use. +UI_BASE_EXPORT std::string GetPngDataUrl(const unsigned char* data, + size_t size); + // Extracts a disposition from click event arguments. |args| should contain // an integer button and booleans alt key, ctrl key, meta key, and shift key // (in that order), starting at |start_index|. @@ -44,9 +50,17 @@ UI_BASE_EXPORT void SetLoadTimeDataDefaults( const std::string& app_locale, base::DictionaryValue* localized_strings); +// Get a CSS declaration for common text styles using provided template. +UI_BASE_EXPORT std::string GetWebUiCssTextDefaults( + const std::string& css_template); + // Get a CSS declaration for common text styles for all of Web UI. UI_BASE_EXPORT std::string GetWebUiCssTextDefaults(); +// Get a CSS declaration for common text styles for Web UI using +// Material Design. +UI_BASE_EXPORT std::string GetWebUiCssTextDefaultsMd(); + // Appends the CSS declaration returned by GetWebUiCssTextDefaults() as an // inline stylesheet. UI_BASE_EXPORT void AppendWebUiCssTextDefaults(std::string* html); diff --git a/chromium/ui/base/win/accessibility_ids_win.h b/chromium/ui/base/win/accessibility_ids_win.h index af8041ce7e1..6b07de52d6b 100644 --- a/chromium/ui/base/win/accessibility_ids_win.h +++ b/chromium/ui/base/win/accessibility_ids_win.h @@ -4,6 +4,8 @@ #ifndef UI_BASE_WIN_ACCESSIBILITY_IDS_WIN_H_ #define UI_BASE_WIN_ACCESSIBILITY_IDS_WIN_H_ +#include <limits.h> + namespace base { namespace win { diff --git a/chromium/ui/base/win/atl_module.h b/chromium/ui/base/win/atl_module.h index f677b435c64..e1468aea07e 100644 --- a/chromium/ui/base/win/atl_module.h +++ b/chromium/ui/base/win/atl_module.h @@ -8,7 +8,6 @@ #include <atlbase.h> #include <atlcom.h> -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/macros.h" diff --git a/chromium/ui/base/win/foreground_helper.h b/chromium/ui/base/win/foreground_helper.h index 8387c13b7ee..b5ca5f0e544 100644 --- a/chromium/ui/base/win/foreground_helper.h +++ b/chromium/ui/base/win/foreground_helper.h @@ -6,6 +6,7 @@ #define UI_BASE_WIN_FOREGROUND_HELPER_H_ #include "base/logging.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/win/window_impl.h" diff --git a/chromium/ui/base/win/hwnd_subclass.cc b/chromium/ui/base/win/hwnd_subclass.cc index 6c9a70c33c1..7cc235ab573 100644 --- a/chromium/ui/base/win/hwnd_subclass.cc +++ b/chromium/ui/base/win/hwnd_subclass.cc @@ -7,8 +7,10 @@ #include <algorithm> #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_vector.h" #include "base/memory/singleton.h" +#include "base/stl_util.h" #include "ui/gfx/win/dpi.h" #include "ui/gfx/win/hwnd_util.h" @@ -109,7 +111,7 @@ HWNDSubclass* HWNDSubclass::GetHwndSubclassForTarget(HWND target) { void HWNDSubclass::AddFilter(HWNDMessageFilter* filter) { DCHECK(filter); - if (std::find(filters_.begin(), filters_.end(), filter) == filters_.end()) + if (!ContainsValue(filters_, filter)) filters_.push_back(filter); } diff --git a/chromium/ui/base/win/hwnd_subclass.h b/chromium/ui/base/win/hwnd_subclass.h index 983d525185f..90386172e07 100644 --- a/chromium/ui/base/win/hwnd_subclass.h +++ b/chromium/ui/base/win/hwnd_subclass.h @@ -8,6 +8,7 @@ #include <windows.h> #include <vector> +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "ui/base/ui_base_export.h" #include "ui/base/view_prop.h" diff --git a/chromium/ui/base/win/hwnd_subclass_unittest.cc b/chromium/ui/base/win/hwnd_subclass_unittest.cc index 979e1385ebf..b811e273966 100644 --- a/chromium/ui/base/win/hwnd_subclass_unittest.cc +++ b/chromium/ui/base/win/hwnd_subclass_unittest.cc @@ -4,7 +4,7 @@ #include "ui/base/win/hwnd_subclass.h" -#include "base/basictypes.h" +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/win/window_impl.h" diff --git a/chromium/ui/base/win/lock_state.h b/chromium/ui/base/win/lock_state.h index be9c912678a..02a7a2d72df 100644 --- a/chromium/ui/base/win/lock_state.h +++ b/chromium/ui/base/win/lock_state.h @@ -5,7 +5,6 @@ #ifndef UI_BASE_WIN_LOCK_STATE_H_ #define UI_BASE_WIN_LOCK_STATE_H_ -#include "base/basictypes.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/win/open_file_name_win.cc b/chromium/ui/base/win/open_file_name_win.cc index 5e5b5b4c5ee..5c2df415a23 100644 --- a/chromium/ui/base/win/open_file_name_win.cc +++ b/chromium/ui/base/win/open_file_name_win.cc @@ -5,6 +5,7 @@ #include "ui/base/win/open_file_name_win.h" #include "base/files/file_path.h" +#include "base/macros.h" #include "base/strings/string_util.h" #include "base/win/windows_version.h" diff --git a/chromium/ui/base/win/open_file_name_win_unittest.cc b/chromium/ui/base/win/open_file_name_win_unittest.cc index e63df7d0e9a..36de27faa96 100644 --- a/chromium/ui/base/win/open_file_name_win_unittest.cc +++ b/chromium/ui/base/win/open_file_name_win_unittest.cc @@ -4,7 +4,10 @@ #include "ui/base/win/open_file_name_win.h" +#include <stddef.h> + #include "base/files/file_path.h" +#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace { diff --git a/chromium/ui/base/win/scoped_ole_initializer.h b/chromium/ui/base/win/scoped_ole_initializer.h index b2e81d22c41..255a68ccc23 100644 --- a/chromium/ui/base/win/scoped_ole_initializer.h +++ b/chromium/ui/base/win/scoped_ole_initializer.h @@ -7,7 +7,7 @@ #include <ole2.h> -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/win/shell.cc b/chromium/ui/base/win/shell.cc index 2a5bd29798d..8dacd14ce4e 100644 --- a/chromium/ui/base/win/shell.cc +++ b/chromium/ui/base/win/shell.cc @@ -16,7 +16,6 @@ #include "base/native_library.h" #include "base/strings/string_util.h" #include "base/threading/thread_restrictions.h" -#include "base/win/metro.h" #include "base/win/scoped_comptr.h" #include "base/win/win_util.h" #include "base/win/windows_version.h" @@ -97,15 +96,15 @@ bool OpenFolderViaShell(const base::FilePath& full_path) { } bool PreventWindowFromPinning(HWND hwnd) { - // This functionality is only available on Win7+. It also doesn't make sense - // to do this for Chrome Metro. - if (base::win::GetVersion() < base::win::VERSION_WIN7 || - base::win::IsMetroProcess()) + DCHECK(hwnd); + + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) return false; + base::win::ScopedComPtr<IPropertyStore> pps; - HRESULT result = SHGetPropertyStoreForWindow( - hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); - if (FAILED(result)) + if (FAILED(SHGetPropertyStoreForWindow(hwnd, + IID_PPV_ARGS(pps.Receive())))) return false; return base::win::SetBooleanValueForPropertyStore( @@ -119,31 +118,32 @@ void SetAppDetailsForWindow(const base::string16& app_id, const base::string16& relaunch_command, const base::string16& relaunch_display_name, HWND hwnd) { - // This functionality is only available on Win7+. It also doesn't make sense - // to do this for Chrome Metro. - if (base::win::GetVersion() < base::win::VERSION_WIN7 || - base::win::IsMetroProcess()) + DCHECK(hwnd); + + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) return; + base::win::ScopedComPtr<IPropertyStore> pps; - HRESULT result = SHGetPropertyStoreForWindow( - hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); - if (S_OK == result) { - if (!app_id.empty()) - base::win::SetAppIdForPropertyStore(pps.get(), app_id.c_str()); - if (!app_icon.empty()) { - base::win::SetStringValueForPropertyStore( - pps.get(), PKEY_AppUserModel_RelaunchIconResource, app_icon.c_str()); - } - if (!relaunch_command.empty()) { - base::win::SetStringValueForPropertyStore( - pps.get(), PKEY_AppUserModel_RelaunchCommand, - relaunch_command.c_str()); - } - if (!relaunch_display_name.empty()) { - base::win::SetStringValueForPropertyStore( - pps.get(), PKEY_AppUserModel_RelaunchDisplayNameResource, - relaunch_display_name.c_str()); - } + if (FAILED(SHGetPropertyStoreForWindow(hwnd, + IID_PPV_ARGS(pps.Receive())))) + return; + + if (!app_id.empty()) + base::win::SetAppIdForPropertyStore(pps.get(), app_id.c_str()); + if (!app_icon.empty()) { + base::win::SetStringValueForPropertyStore( + pps.get(), PKEY_AppUserModel_RelaunchIconResource, app_icon.c_str()); + } + if (!relaunch_command.empty()) { + base::win::SetStringValueForPropertyStore( + pps.get(), PKEY_AppUserModel_RelaunchCommand, + relaunch_command.c_str()); + } + if (!relaunch_display_name.empty()) { + base::win::SetStringValueForPropertyStore( + pps.get(), PKEY_AppUserModel_RelaunchDisplayNameResource, + relaunch_display_name.c_str()); } } @@ -173,6 +173,32 @@ void SetRelaunchDetailsForWindow(const base::string16& relaunch_command, hwnd); } +void ClearWindowPropertyStore(HWND hwnd) { + DCHECK(hwnd); + + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + + base::win::ScopedComPtr<IPropertyStore> pps; + if (FAILED(SHGetPropertyStoreForWindow(hwnd, + IID_PPV_ARGS(pps.Receive())))) + return; + + DWORD property_count; + if (FAILED(pps->GetCount(&property_count))) + return; + + PROPVARIANT empty_property_variant = {}; + for (DWORD i = 0; i < property_count; i++) { + PROPERTYKEY key; + if (SUCCEEDED(pps->GetAt(i, &key))) + pps->SetValue(key, empty_property_variant); + } + + pps->Commit(); +} + bool IsAeroGlassEnabled() { // For testing in Win8 (where it is not possible to disable composition) the // user can specify this command line switch to mimic the behavior. In this diff --git a/chromium/ui/base/win/shell.h b/chromium/ui/base/win/shell.h index 4031de6d9ae..458074c6ff9 100644 --- a/chromium/ui/base/win/shell.h +++ b/chromium/ui/base/win/shell.h @@ -76,6 +76,9 @@ UI_BASE_EXPORT void SetRelaunchDetailsForWindow( const base::string16& display_name, HWND hwnd); +// Clears the Window Property Store on an HWND. +UI_BASE_EXPORT void ClearWindowPropertyStore(HWND hwnd); + // Returns true if composition is available and turned on on the current // platform. UI_BASE_EXPORT bool IsAeroGlassEnabled(); diff --git a/chromium/ui/base/win/window_event_target.h b/chromium/ui/base/win/window_event_target.h index 8ec6360f6a8..e87b519a346 100644 --- a/chromium/ui/base/win/window_event_target.h +++ b/chromium/ui/base/win/window_event_target.h @@ -7,7 +7,6 @@ #include <windows.h> -#include "base/basictypes.h" #include "ui/base/ui_base_export.h" namespace ui { diff --git a/chromium/ui/base/x/selection_owner.h b/chromium/ui/base/x/selection_owner.h index 7bea5ad485e..f3bec33aca8 100644 --- a/chromium/ui/base/x/selection_owner.h +++ b/chromium/ui/base/x/selection_owner.h @@ -5,10 +5,12 @@ #ifndef UI_BASE_X_SELECTION_OWNER_H_ #define UI_BASE_X_SELECTION_OWNER_H_ +#include <stddef.h> + #include <vector> -#include "base/basictypes.h" #include "base/callback.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/time/time.h" #include "base/timer/timer.h" diff --git a/chromium/ui/base/x/selection_requestor.h b/chromium/ui/base/x/selection_requestor.h index 2e39166617a..8be12c67bd4 100644 --- a/chromium/ui/base/x/selection_requestor.h +++ b/chromium/ui/base/x/selection_requestor.h @@ -5,11 +5,13 @@ #ifndef UI_BASE_X_SELECTION_REQUESTOR_H_ #define UI_BASE_X_SELECTION_REQUESTOR_H_ +#include <stddef.h> + #include <vector> -#include "base/basictypes.h" #include "base/callback.h" #include "base/event_types.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/time/time.h" #include "base/timer/timer.h" diff --git a/chromium/ui/base/x/selection_requestor_unittest.cc b/chromium/ui/base/x/selection_requestor_unittest.cc index 4095d44bb27..b292f9395d7 100644 --- a/chromium/ui/base/x/selection_requestor_unittest.cc +++ b/chromium/ui/base/x/selection_requestor_unittest.cc @@ -4,6 +4,9 @@ #include "ui/base/x/selection_requestor.h" +#include <stddef.h> + +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" diff --git a/chromium/ui/base/x/selection_utils.cc b/chromium/ui/base/x/selection_utils.cc index cc9afbed95c..af84c4babbe 100644 --- a/chromium/ui/base/x/selection_utils.cc +++ b/chromium/ui/base/x/selection_utils.cc @@ -4,6 +4,8 @@ #include "ui/base/x/selection_utils.h" +#include <stdint.h> + #include <set> #include "base/i18n/icu_string_conversions.h" diff --git a/chromium/ui/base/x/selection_utils.h b/chromium/ui/base/x/selection_utils.h index 9eca5beb4ab..1c4bcbdbc8c 100644 --- a/chromium/ui/base/x/selection_utils.h +++ b/chromium/ui/base/x/selection_utils.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_X_SELECTION_UTILS_H_ #define UI_BASE_X_SELECTION_UTILS_H_ +#include <stddef.h> #include <X11/Xlib.h> // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. @@ -12,7 +13,6 @@ #include <map> -#include "base/basictypes.h" #include "base/memory/ref_counted_memory.h" #include "ui/base/clipboard/clipboard.h" #include "ui/base/ui_base_export.h" diff --git a/chromium/ui/base/x/x11_foreign_window_manager.cc b/chromium/ui/base/x/x11_foreign_window_manager.cc index ded4bfe3fbe..4e739d6c3c6 100644 --- a/chromium/ui/base/x/x11_foreign_window_manager.cc +++ b/chromium/ui/base/x/x11_foreign_window_manager.cc @@ -4,6 +4,7 @@ #include "ui/base/x/x11_foreign_window_manager.h" +#include <stddef.h> #include <X11/Xlib.h> #include "base/compiler_specific.h" diff --git a/chromium/ui/base/x/x11_foreign_window_manager.h b/chromium/ui/base/x/x11_foreign_window_manager.h index a9167b15598..55da51e2576 100644 --- a/chromium/ui/base/x/x11_foreign_window_manager.h +++ b/chromium/ui/base/x/x11_foreign_window_manager.h @@ -8,8 +8,8 @@ #include <map> #include <vector> -#include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/x/x11_types.h" diff --git a/chromium/ui/base/x/x11_menu_list.cc b/chromium/ui/base/x/x11_menu_list.cc index 08f2c7d57a3..a7c2fda8117 100644 --- a/chromium/ui/base/x/x11_menu_list.cc +++ b/chromium/ui/base/x/x11_menu_list.cc @@ -4,6 +4,8 @@ #include "ui/base/x/x11_menu_list.h" +#include <algorithm> + #include "base/memory/singleton.h" #include "ui/base/x/x11_util.h" diff --git a/chromium/ui/base/x/x11_menu_list.h b/chromium/ui/base/x/x11_menu_list.h index 00c824e6a66..6986f1cc84c 100644 --- a/chromium/ui/base/x/x11_menu_list.h +++ b/chromium/ui/base/x/x11_menu_list.h @@ -7,7 +7,7 @@ #include <vector> -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/base/ui_base_export.h" #include "ui/gfx/x/x11_types.h" diff --git a/chromium/ui/base/x/x11_util.cc b/chromium/ui/base/x/x11_util.cc index f7b29fdf6a7..9e55a4664cf 100644 --- a/chromium/ui/base/x/x11_util.cc +++ b/chromium/ui/base/x/x11_util.cc @@ -23,16 +23,19 @@ #include "base/bind.h" #include "base/logging.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/message_loop/message_loop.h" #include "base/metrics/histogram.h" +#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/sys_byteorder.h" #include "base/threading/thread.h" #include "base/trace_event/trace_event.h" +#include "build/build_config.h" #include "skia/ext/image_operations.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkPostConfig.h" @@ -53,6 +56,11 @@ #include "ui/gfx/skia_util.h" #include "ui/gfx/x/x11_error_tracker.h" +#if !defined(OS_CHROMEOS) +#include "base/command_line.h" +#include "ui/gfx/x/x11_switches.h" +#endif + #if defined(OS_FREEBSD) #include <sys/sysctl.h> #include <sys/types.h> @@ -345,7 +353,7 @@ XcursorImage* SkBitmapToXcursorImage(const SkBitmap* cursor_image, skia::ImageOperations::RESIZE_BETTER, static_cast<int>(cursor_image->width() * scale), static_cast<int>(cursor_image->height() * scale)); - hotspot_point = gfx::ToFlooredPoint(gfx::ScalePoint(hotspot, scale)); + hotspot_point = gfx::ScaleToFlooredPoint(hotspot, scale); needs_scale = true; } @@ -366,9 +374,7 @@ XcursorImage* SkBitmapToXcursorImage(const SkBitmap* cursor_image, return image; } - -int CoalescePendingMotionEvents(const XEvent* xev, - XEvent* last_event) { +int CoalescePendingMotionEvents(const XEvent* xev, XEvent* last_event) { XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); int num_coalesced = 0; XDisplay* display = xev->xany.display; @@ -397,7 +403,9 @@ int CoalescePendingMotionEvents(const XEvent* xev, if (next_event.type == GenericEvent && next_event.xgeneric.evtype == event_type && !ui::DeviceDataManagerX11::GetInstance()->IsCMTGestureEvent( - &next_event)) { + next_event) && + ui::DeviceDataManagerX11::GetInstance()->GetScrollClassEventDetail( + next_event) == SCROLL_TYPE_NO_SCROLL) { XIDeviceEvent* next_xievent = static_cast<XIDeviceEvent*>(next_event.xcookie.data); // Confirm that the motion event is targeted at the same window @@ -406,8 +414,7 @@ int CoalescePendingMotionEvents(const XEvent* xev, xievent->child == next_xievent->child && xievent->detail == next_xievent->detail && xievent->buttons.mask_len == next_xievent->buttons.mask_len && - (memcmp(xievent->buttons.mask, - next_xievent->buttons.mask, + (memcmp(xievent->buttons.mask, next_xievent->buttons.mask, xievent->buttons.mask_len) == 0) && xievent->mods.base == next_xievent->mods.base && xievent->mods.latched == next_xievent->mods.latched && @@ -553,10 +560,8 @@ bool IsWindowVisible(XID window) { std::vector<XAtom> wm_states; if (GetAtomArrayProperty(window, "_NET_WM_STATE", &wm_states)) { XAtom hidden_atom = GetAtom("_NET_WM_STATE_HIDDEN"); - if (std::find(wm_states.begin(), wm_states.end(), hidden_atom) != - wm_states.end()) { + if (ContainsValue(wm_states, hidden_atom)) return false; - } } // Some compositing window managers (notably kwin) do not actually unmap @@ -1409,6 +1414,64 @@ void LogErrorEventDescription(XDisplay* dpy, << " (" << request_str << ")"; } +#if !defined(OS_CHROMEOS) +void ChooseVisualForWindow(Visual** visual, int* depth) { + static Visual* s_visual = NULL; + static int s_depth = 0; + + if (!s_visual) { + XDisplay* display = gfx::GetXDisplay(); + XAtom NET_WM_CM_S0 = XInternAtom(display, "_NET_WM_CM_S0", False); + + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableTransparentVisuals) && + XGetSelectionOwner(display, NET_WM_CM_S0) != None) { + // Choose the first ARGB8888 visual + XVisualInfo visual_template; + visual_template.screen = 0; + + int visuals_len; + gfx::XScopedPtr<XVisualInfo[]> visual_list(XGetVisualInfo( + display, VisualScreenMask, &visual_template, &visuals_len)); + for (int i = 0; i < visuals_len; ++i) { + // Why support only 8888 ARGB? Because it's all that GTK+ supports. In + // gdkvisual-x11.cc, they look for this specific visual and use it for + // all their alpha channel using needs. + // + // TODO(erg): While the following does find a valid visual, some GL + // drivers + // don't believe that this has an alpha channel. According to marcheu@, + // this should work on open source driver though. (It doesn't work with + // NVidia's binaries currently.) http://crbug.com/369209 + const XVisualInfo& info = visual_list[i]; + if (info.depth == 32 && info.visual->red_mask == 0xff0000 && + info.visual->green_mask == 0x00ff00 && + info.visual->blue_mask == 0x0000ff) { + s_visual = info.visual; + s_depth = info.depth; + break; + } + } + } else { + XWindowAttributes windowAttribs; + Window root = XDefaultRootWindow(display); + Status status = XGetWindowAttributes(display, root, &windowAttribs); + DCHECK(status != 0); + s_visual = windowAttribs.visual; + s_depth = windowAttribs.depth; + } + } // !s_visual + + DCHECK(s_visual); + DCHECK(s_depth > 0); + + if (visual) + *visual = s_visual; + if (depth) + *depth = s_depth; +} +#endif + // ---------------------------------------------------------------------------- // End of x11_util_internal.h diff --git a/chromium/ui/base/x/x11_util.h b/chromium/ui/base/x/x11_util.h index d32101fa6a8..c3c9c2b3b51 100644 --- a/chromium/ui/base/x/x11_util.h +++ b/chromium/ui/base/x/x11_util.h @@ -11,11 +11,13 @@ // we use a void* for Visual*). The Xlib headers are highly polluting so we try // hard to limit their spread into the rest of the code. +#include <stddef.h> + #include <string> #include <vector> -#include "base/basictypes.h" #include "base/event_types.h" +#include "base/macros.h" #include "base/memory/ref_counted_memory.h" #include "ui/base/ui_base_export.h" #include "ui/events/event_constants.h" diff --git a/chromium/ui/base/x/x11_util_internal.h b/chromium/ui/base/x/x11_util_internal.h index f663fc5ac87..d58eccfc905 100644 --- a/chromium/ui/base/x/x11_util_internal.h +++ b/chromium/ui/base/x/x11_util_internal.h @@ -18,6 +18,7 @@ extern "C" { #include <X11/Xlib.h> } +#include "build/build_config.h" #include "ui/base/ui_base_export.h" namespace ui { @@ -44,6 +45,15 @@ UI_BASE_EXPORT void SetX11ErrorHandlers(XErrorHandler error_handler, UI_BASE_EXPORT void LogErrorEventDescription(Display* dpy, const XErrorEvent& error_event); +// -------------------------------------------------------------------------- +// Selects a visual with a preference for alpha support on compositing window +// managers. The caller must compare depth to 32 to know if the returned visual +// supports transparency. NULL parameters are allowed to install or query the +// cached visual and depth. +#if !defined(OS_CHROMEOS) +UI_BASE_EXPORT void ChooseVisualForWindow(Visual** visual, int* depth); +#endif + } // namespace ui #endif // UI_BASE_X_X11_UTIL_INTERNAL_H_ |