views: Show menubar's accelerator when "Alt" is pressed.
This commit is contained in:
parent
965f2b1b6b
commit
e9536508a5
5 changed files with 30 additions and 1 deletions
|
@ -572,6 +572,11 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||||
const content::NativeWebKeyboardEvent& event) {
|
const content::NativeWebKeyboardEvent& event) {
|
||||||
keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
|
keyboard_event_handler_->HandleKeyboardEvent(event, GetFocusManager());
|
||||||
|
|
||||||
|
if (menu_bar_ && menu_bar_visible_ && IsAltKey(event)) {
|
||||||
|
menu_bar_->SetAcceleratorVisibility(
|
||||||
|
event.type == blink::WebInputEvent::RawKeyDown);
|
||||||
|
}
|
||||||
|
|
||||||
if (!menu_bar_autohide_)
|
if (!menu_bar_autohide_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -627,6 +632,10 @@ void NativeWindowViews::SetMenuBarVisibility(bool visible) {
|
||||||
if (!menu_bar_)
|
if (!menu_bar_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Always show the accelerator when the auto-hide menu bar shows.
|
||||||
|
if (menu_bar_autohide_)
|
||||||
|
menu_bar_->SetAcceleratorVisibility(visible);
|
||||||
|
|
||||||
menu_bar_visible_ = visible;
|
menu_bar_visible_ = visible;
|
||||||
if (visible) {
|
if (visible) {
|
||||||
DCHECK_EQ(child_count(), 1);
|
DCHECK_EQ(child_count(), 1);
|
||||||
|
|
|
@ -85,6 +85,11 @@ void MenuBar::SetMenu(ui::MenuModel* model) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuBar::SetAcceleratorVisibility(bool visible) {
|
||||||
|
for (int i = 0; i < child_count(); ++i)
|
||||||
|
static_cast<SubmenuButton*>(child_at(i))->SetAcceleratorVisibility(visible);
|
||||||
|
}
|
||||||
|
|
||||||
int MenuBar::GetItemCount() const {
|
int MenuBar::GetItemCount() const {
|
||||||
return menu_model_->GetItemCount();
|
return menu_model_->GetItemCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ class MenuBar : public views::View,
|
||||||
// Replaces current menu with a new one.
|
// Replaces current menu with a new one.
|
||||||
void SetMenu(ui::MenuModel* menu_model);
|
void SetMenu(ui::MenuModel* menu_model);
|
||||||
|
|
||||||
|
// Shows underline under accelerators.
|
||||||
|
void SetAcceleratorVisibility(bool visible);
|
||||||
|
|
||||||
// Returns there are how many items in the root menu.
|
// Returns there are how many items in the root menu.
|
||||||
int GetItemCount() const;
|
int GetItemCount() const;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ SubmenuButton::SubmenuButton(views::ButtonListener* listener,
|
||||||
views::MenuButtonListener* menu_button_listener)
|
views::MenuButtonListener* menu_button_listener)
|
||||||
: views::MenuButton(listener, FilterAccecelator(title),
|
: views::MenuButton(listener, FilterAccecelator(title),
|
||||||
menu_button_listener, false),
|
menu_button_listener, false),
|
||||||
|
show_underline_(false),
|
||||||
underline_start_(-1),
|
underline_start_(-1),
|
||||||
underline_end_(-1),
|
underline_end_(-1),
|
||||||
text_width_(0),
|
text_width_(0),
|
||||||
|
@ -40,6 +41,14 @@ SubmenuButton::SubmenuButton(views::ButtonListener* listener,
|
||||||
SubmenuButton::~SubmenuButton() {
|
SubmenuButton::~SubmenuButton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SubmenuButton::SetAcceleratorVisibility(bool visible) {
|
||||||
|
if (visible == show_underline_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
show_underline_ = visible;
|
||||||
|
SchedulePaint();
|
||||||
|
}
|
||||||
|
|
||||||
void SubmenuButton::SetUnderlineColor(SkColor color) {
|
void SubmenuButton::SetUnderlineColor(SkColor color) {
|
||||||
underline_color_ = color;
|
underline_color_ = color;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +56,7 @@ void SubmenuButton::SetUnderlineColor(SkColor color) {
|
||||||
void SubmenuButton::OnPaint(gfx::Canvas* canvas) {
|
void SubmenuButton::OnPaint(gfx::Canvas* canvas) {
|
||||||
views::MenuButton::OnPaint(canvas);
|
views::MenuButton::OnPaint(canvas);
|
||||||
|
|
||||||
if (underline_start_ != underline_end_) {
|
if (show_underline_ && (underline_start_ != underline_end_)) {
|
||||||
int padding = (width() - text_width_) / 2;
|
int padding = (width() - text_width_) / 2;
|
||||||
int underline_height = (height() + text_height_) / 2 - 2;
|
int underline_height = (height() + text_height_) / 2 - 2;
|
||||||
canvas->DrawLine(gfx::Point(underline_start_ + padding, underline_height),
|
canvas->DrawLine(gfx::Point(underline_start_ + padding, underline_height),
|
||||||
|
|
|
@ -17,6 +17,7 @@ class SubmenuButton : public views::MenuButton {
|
||||||
views::MenuButtonListener* menu_button_listener);
|
views::MenuButtonListener* menu_button_listener);
|
||||||
virtual ~SubmenuButton();
|
virtual ~SubmenuButton();
|
||||||
|
|
||||||
|
void SetAcceleratorVisibility(bool visible);
|
||||||
void SetUnderlineColor(SkColor color);
|
void SetUnderlineColor(SkColor color);
|
||||||
|
|
||||||
// views::MenuButton:
|
// views::MenuButton:
|
||||||
|
@ -28,6 +29,8 @@ class SubmenuButton : public views::MenuButton {
|
||||||
void GetCharacterPosition(
|
void GetCharacterPosition(
|
||||||
const base::string16& text, int index, int* pos);
|
const base::string16& text, int index, int* pos);
|
||||||
|
|
||||||
|
bool show_underline_;
|
||||||
|
|
||||||
int underline_start_;
|
int underline_start_;
|
||||||
int underline_end_;
|
int underline_end_;
|
||||||
int text_width_;
|
int text_width_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue