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_impl.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/views/menu_button_view.h"
|
|
|
|
#include "libcef/browser/views/window_impl.h"
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
#include "ui/gfx/canvas.h"
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefMenuButton> CefMenuButton::CreateMenuButton(
|
|
|
|
CefRefPtr<CefMenuButtonDelegate> delegate,
|
|
|
|
const CefString& text,
|
|
|
|
bool with_frame,
|
|
|
|
bool with_menu_marker) {
|
|
|
|
return CefMenuButtonImpl::Create(delegate, text, with_frame,
|
|
|
|
with_menu_marker);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefMenuButtonImpl> CefMenuButtonImpl::Create(
|
|
|
|
CefRefPtr<CefMenuButtonDelegate> delegate,
|
|
|
|
const CefString& text,
|
|
|
|
bool with_frame,
|
|
|
|
bool with_menu_marker) {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
|
|
|
DCHECK(delegate);
|
|
|
|
if (!delegate)
|
|
|
|
return nullptr;
|
|
|
|
CefRefPtr<CefMenuButtonImpl> menu_button = new CefMenuButtonImpl(delegate);
|
|
|
|
menu_button->Initialize();
|
|
|
|
if (!text.empty())
|
|
|
|
menu_button->SetText(text);
|
2017-05-31 17:33:30 +02:00
|
|
|
if (with_frame) {
|
2017-09-06 23:40:58 +02:00
|
|
|
menu_button->root_view()->SetStyleDeprecated(views::Button::STYLE_BUTTON);
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
menu_button->root_view()->set_show_menu_marker(with_menu_marker);
|
|
|
|
return menu_button;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMenuButtonImpl::ShowMenu(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
cef_menu_anchor_position_t anchor_position) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
CefRefPtr<CefWindow> window =
|
|
|
|
view_util::GetWindowFor(root_view()->GetWidget());
|
|
|
|
CefWindowImpl* window_impl = static_cast<CefWindowImpl*>(window.get());
|
|
|
|
if (window_impl) {
|
|
|
|
window_impl->ShowMenu(root_view(), menu_model, screen_point,
|
|
|
|
anchor_position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 19:05:27 +01:00
|
|
|
void CefMenuButtonImpl::TriggerMenu() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
root_view()->Activate(nullptr);
|
|
|
|
}
|
|
|
|
|
2017-02-23 21:24:45 +01:00
|
|
|
void CefMenuButtonImpl::SetFocusable(bool focusable) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<CefMenuButtonView*>(root_view())
|
|
|
|
->SetDrawStringsFlags(focusable ? gfx::Canvas::SHOW_PREFIX
|
|
|
|
: gfx::Canvas::HIDE_PREFIX);
|
2017-02-23 21:24:45 +01:00
|
|
|
ParentClass::SetFocusable(focusable);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefMenuButtonImpl::CefMenuButtonImpl(CefRefPtr<CefMenuButtonDelegate> delegate)
|
|
|
|
: ParentClass(delegate) {
|
|
|
|
DCHECK(delegate);
|
|
|
|
}
|
|
|
|
|
|
|
|
views::MenuButton* CefMenuButtonImpl::CreateRootView() {
|
|
|
|
return new CefMenuButtonView(delegate());
|
|
|
|
}
|
2016-07-21 23:21:32 +02:00
|
|
|
|
|
|
|
void CefMenuButtonImpl::InitializeRootView() {
|
|
|
|
static_cast<CefMenuButtonView*>(root_view())->Initialize();
|
|
|
|
}
|