2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/views/menu_button_view.h"
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
#include "ui/gfx/canvas.h"
|
2019-06-05 16:15:45 +02:00
|
|
|
#include "ui/views/controls/button/menu_button_controller.h"
|
2017-02-25 06:03:31 +01:00
|
|
|
#include "ui/views/controls/menu/menu_config.h"
|
2017-02-23 21:24:45 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ButtonPressedLock : public CefMenuButtonPressedLock {
|
|
|
|
public:
|
|
|
|
explicit ButtonPressedLock(views::MenuButton* menu_button)
|
2019-06-05 16:15:45 +02:00
|
|
|
: pressed_lock_(menu_button->button_controller()) {}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
private:
|
2019-04-16 16:38:48 +02:00
|
|
|
views::MenuButtonController::PressedLock pressed_lock_;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(ButtonPressedLock);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ButtonPressedLock);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefMenuButtonView::CefMenuButtonView(CefMenuButtonDelegate* cef_delegate)
|
2016-01-19 21:09:01 +01:00
|
|
|
: ParentClass(cef_delegate) {
|
|
|
|
DCHECK(cef_delegate);
|
|
|
|
}
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
void CefMenuButtonView::Initialize() {
|
|
|
|
ParentClass::Initialize();
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
SetDrawStringsFlags(IsFocusable() ? gfx::Canvas::SHOW_PREFIX
|
|
|
|
: gfx::Canvas::HIDE_PREFIX);
|
2017-02-25 06:03:31 +01:00
|
|
|
|
|
|
|
// Use the same default font as MenuItemView.
|
|
|
|
SetFontList(views::MenuConfig::instance().font_list);
|
2017-02-23 21:24:45 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefMenuButton> CefMenuButtonView::GetCefMenuButton() const {
|
|
|
|
CefRefPtr<CefMenuButton> menu_button = GetCefLabelButton()->AsMenuButton();
|
|
|
|
DCHECK(menu_button);
|
|
|
|
return menu_button;
|
|
|
|
}
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
void CefMenuButtonView::SetDrawStringsFlags(int flags) {
|
|
|
|
label()->SetDrawStringsFlags(flags);
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:15:45 +02:00
|
|
|
void CefMenuButtonView::OnMenuButtonClicked(views::Button* source,
|
2016-01-19 21:09:01 +01:00
|
|
|
const gfx::Point& point,
|
|
|
|
const ui::Event* event) {
|
2019-06-05 16:15:45 +02:00
|
|
|
cef_delegate()->OnMenuButtonPressed(
|
|
|
|
GetCefMenuButton(), CefPoint(point.x(), point.y()),
|
|
|
|
new ButtonPressedLock(static_cast<views::MenuButton*>(source)));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|