submenu_button.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
  6. #include <string>
  7. #include "ui/base/metadata/metadata_header_macros.h"
  8. #include "ui/base/metadata/metadata_impl_macros.h"
  9. #include "ui/views/controls/button/menu_button.h"
  10. namespace ui {
  11. struct AXNodeData;
  12. }
  13. namespace electron {
  14. // Special button that used by menu bar to show submenus.
  15. class SubmenuButton : public views::MenuButton {
  16. METADATA_HEADER(SubmenuButton, views::MenuButton)
  17. public:
  18. SubmenuButton(PressedCallback callback,
  19. const std::u16string& title,
  20. const SkColor& background_color);
  21. ~SubmenuButton() override;
  22. // disable copy
  23. SubmenuButton(const SubmenuButton&) = delete;
  24. SubmenuButton& operator=(const SubmenuButton&) = delete;
  25. void SetAcceleratorVisibility(bool visible);
  26. void SetUnderlineColor(SkColor color);
  27. char16_t accelerator() const { return accelerator_; }
  28. void PaintButtonContents(gfx::Canvas* canvas) override;
  29. private:
  30. bool GetUnderlinePosition(const std::u16string& text,
  31. char16_t* accelerator,
  32. int* start,
  33. int* end) const;
  34. void GetCharacterPosition(const std::u16string& text,
  35. int index,
  36. int* pos) const;
  37. char16_t accelerator_ = 0;
  38. bool show_underline_ = false;
  39. int underline_start_ = 0;
  40. int underline_end_ = 0;
  41. int text_width_ = 0;
  42. int text_height_ = 0;
  43. SkColor underline_color_ = SK_ColorBLACK;
  44. SkColor background_color_;
  45. };
  46. } // namespace electron
  47. #endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_