platform_style.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/views/style/platform_style.h"
  5. #include "build/build_config.h"
  6. #include "build/chromeos_buildflags.h"
  7. #include "ui/base/resource/resource_bundle.h"
  8. #include "ui/gfx/range/range.h"
  9. #include "ui/gfx/utf16_indexing.h"
  10. #include "ui/native_theme/native_theme.h"
  11. #include "ui/views/background.h"
  12. #include "ui/views/buildflags.h"
  13. #include "ui/views/controls/button/label_button.h"
  14. #include "ui/views/controls/button/label_button_border.h"
  15. #include "ui/views/controls/focusable_border.h"
  16. #include "ui/views/controls/scrollbar/scroll_bar_views.h"
  17. #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
  18. #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
  19. #endif
  20. namespace views {
  21. #if BUILDFLAG(IS_WIN)
  22. const bool PlatformStyle::kIsOkButtonLeading = true;
  23. #else
  24. const bool PlatformStyle::kIsOkButtonLeading = false;
  25. #endif
  26. #if !BUILDFLAG(IS_MAC)
  27. const int PlatformStyle::kMinLabelButtonWidth = 70;
  28. const int PlatformStyle::kMinLabelButtonHeight = 33;
  29. const bool PlatformStyle::kDialogDefaultButtonCanBeCancel = true;
  30. const bool PlatformStyle::kSelectWordOnRightClick = false;
  31. const bool PlatformStyle::kSelectAllOnRightClickWhenUnfocused = false;
  32. const Button::KeyClickAction PlatformStyle::kKeyClickActionOnSpace =
  33. Button::KeyClickAction::kOnKeyRelease;
  34. const bool PlatformStyle::kReturnClicksFocusedControl = true;
  35. const bool PlatformStyle::kTableViewSupportsKeyboardNavigationByCell = true;
  36. const bool PlatformStyle::kTreeViewSelectionPaintsEntireRow = false;
  37. const bool PlatformStyle::kUseRipples = true;
  38. const bool PlatformStyle::kTextfieldUsesDragCursorWhenDraggable = true;
  39. const bool PlatformStyle::kInactiveWidgetControlsAppearDisabled = false;
  40. const View::FocusBehavior PlatformStyle::kDefaultFocusBehavior =
  41. View::FocusBehavior::ALWAYS;
  42. // Linux clips bubble windows that extend outside their parent window
  43. // bounds.
  44. const bool PlatformStyle::kAdjustBubbleIfOffscreen =
  45. // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
  46. // of lacros-chrome is complete.
  47. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
  48. false;
  49. #else
  50. true;
  51. #endif
  52. // static
  53. std::unique_ptr<ScrollBar> PlatformStyle::CreateScrollBar(bool is_horizontal) {
  54. #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
  55. return std::make_unique<OverlayScrollBar>(is_horizontal);
  56. #else
  57. return std::make_unique<ScrollBarViews>(is_horizontal);
  58. #endif
  59. }
  60. // static
  61. void PlatformStyle::OnTextfieldEditFailed() {}
  62. // static
  63. gfx::Range PlatformStyle::RangeToDeleteBackwards(const std::u16string& text,
  64. size_t cursor_position) {
  65. // Delete one code point, which may be two UTF-16 words.
  66. size_t previous_grapheme_index =
  67. gfx::UTF16OffsetToIndex(text, cursor_position, -1);
  68. return gfx::Range(cursor_position, previous_grapheme_index);
  69. }
  70. #endif // !BUILDFLAG(IS_MAC)
  71. } // namespace views