electron/atom/browser/ui/views/submenu_button.h
Charles Kerr 558ef7352d
Better GTK+ Menu color support (#12300)
* Better GTK+ Menu color support

 * Fix 'invisible menu' issue (#12275)

 * Now updates menu text color when focus changes!

 * Better caching of colors when system theme changes

 * Removed all GTK+ deprecation warnings from menubar

* Don't highlight menu text on mouseover in GTK+

* Fix textColor declaration scope error

* Simplify FocusManager connection management a bit

* Make the linter happy

* Decouple MenuBar view recoloring from rebuilding

This way we don't need to rebuild the subview each time a recolor
is needed, e.g. when window focus changes or the system theme changes

* Don't iterate child views if we don't need to

* Move variable declaration outside of a loop

* More efficient iteration of MenuBar children

* Cleaner MenuButton bounds testing

* Fix oops

* Add a nullptr check in MenuBar::GetItemCount()

* Simplify iteration in MenuBar::RebuildChildren()

* Make the linter happy

* Fix signed-unsigned comparison

* Remove declarations of nonexistent methods

* Make SubmenuButton accessor const

* Cleaner accelerator iteration

* Windows fixes
2018-03-17 06:37:36 +09:00

56 lines
1.6 KiB
C++

// Copyright (c) 2014 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
#define ATOM_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/controls/button/menu_button.h"
namespace atom {
// Special button that used by menu bar to show submenus.
class SubmenuButton : public views::MenuButton {
public:
SubmenuButton(const base::string16& title,
views::MenuButtonListener* menu_button_listener,
const SkColor& background_color);
virtual ~SubmenuButton();
void SetAcceleratorVisibility(bool visible);
void SetUnderlineColor(SkColor color);
base::char16 accelerator() const { return accelerator_; }
// views::MenuButton:
void PaintButtonContents(gfx::Canvas* canvas) override;
// views::InkDropHostView:
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override;
private:
bool GetUnderlinePosition(const base::string16& text,
base::char16* accelerator,
int* start, int* end) const;
void GetCharacterPosition(
const base::string16& text, int index, int* pos) const;
base::char16 accelerator_;
bool show_underline_;
int underline_start_;
int underline_end_;
int text_width_;
int text_height_;
SkColor underline_color_;
SkColor background_color_;
DISALLOW_COPY_AND_ASSIGN(SubmenuButton);
};
} // namespace atom
#endif // ATOM_BROWSER_UI_VIEWS_SUBMENU_BUTTON_H_