views: Fix activating lower case accelerators.

This commit is contained in:
Cheng Zhao 2014-08-18 16:05:41 +08:00
Родитель 1dabd20d99
Коммит 6ccec45c61
2 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -34,11 +34,10 @@ SubmenuButton::SubmenuButton(views::ButtonListener* listener,
text_width_(0), text_width_(0),
text_height_(0), text_height_(0),
underline_color_(SK_ColorBLACK) { underline_color_(SK_ColorBLACK) {
if (GetUnderlinePosition(title, &underline_start_, &underline_end_)) { if (GetUnderlinePosition(title, &accelerator_, &underline_start_,
&underline_end_))
gfx::Canvas::SizeStringInt(text(), font_list(), &text_width_, gfx::Canvas::SizeStringInt(text(), font_list(), &text_width_,
&text_height_, 0, 0); &text_height_, 0, 0);
accelerator_ = text()[underline_start_];
}
} }
SubmenuButton::~SubmenuButton() { SubmenuButton::~SubmenuButton() {
@ -68,11 +67,13 @@ void SubmenuButton::OnPaint(gfx::Canvas* canvas) {
} }
} }
bool SubmenuButton::GetUnderlinePosition( bool SubmenuButton::GetUnderlinePosition(const base::string16& text,
const base::string16& text, int* start, int* end) { base::char16* accelerator,
int* start, int* end) {
int pos, span; int pos, span;
base::string16 trimmed = gfx::RemoveAcceleratorChar(text, '&', &pos, &span); base::string16 trimmed = gfx::RemoveAcceleratorChar(text, '&', &pos, &span);
if (pos > -1 && span != 0) { if (pos > -1 && span != 0) {
*accelerator = base::ToUpperASCII(trimmed[pos]);
GetCharacterPosition(trimmed, pos, start); GetCharacterPosition(trimmed, pos, start);
GetCharacterPosition(trimmed, pos + span, end); GetCharacterPosition(trimmed, pos + span, end);
return true; return true;

Просмотреть файл

@ -26,8 +26,9 @@ class SubmenuButton : public views::MenuButton {
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
private: private:
bool GetUnderlinePosition( bool GetUnderlinePosition(const base::string16& text,
const base::string16& text, int* start, int* end); base::char16* accelerator,
int* start, int* end);
void GetCharacterPosition( void GetCharacterPosition(
const base::string16& text, int index, int* pos); const base::string16& text, int index, int* pos);