mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Implement Views framework on Windows and Linux (issue #1749).
- Add Views header files in a new include/views directory. - Add initial top-level window (CefWindow), control (CefBrowserView, CefLabelButton, CefMenuButton, CefPanel, CefScrollView, CefTextfield) and layout (CefBoxLayout, CefFlowLayout) support. See libcef/browser/views/view_impl.h comments for implementation details. - Add Views example usage in cefclient and cefsimple and Views unit tests in cef_unittests. Pass the `--use-views` command-line flag to cefclient, cefsimple and cef_unittests to run using the Views framework instead of platform APIs. For cefclient and cefsimple this will create the browser window and all related functionality using the Views framework. For cef_unittests this will run all tests (except OSR tests) in a Views-based browser window. Views- specific unit tests (`--gtest_filter=Views*`) will be run even if the the `--use-views` flag is not specified. - Pass the `--hide-frame` command-line flag to cefclient to demo a frameless Views-based browser window. - Pass the `--hide-controls` command-line flag to cefclient to demo a browser window without top controls. This also works in non-Views mode. - Pass the `--enable-high-dpi-support` command-line flag to cef_unittests on Windows to test high-DPI support on a display that supports it. - Add CefImage for reading/writing image file formats. - Add CefBrowser::DownloadImage() for downloading image URLs as a CefImage representation. This is primarily for loading favicons. - Add CefMenuModel::CreateMenuModel() and CefMenuModelDelegate for creating custom menus. This is primarily for use with CefMenuButton. - Add CefBrowser::TryCloseBrowser() helper for closing a browser. Also improve related documentation in cef_life_span_handler.h. - Rename cef_page_range_t to cef_range_t. It is now also used by CefTextfield. - Remove CefLifeSpanHandler::RunModal() which is never called. - Add draggable regions example to cefclient.
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
@@ -162,6 +164,18 @@ class CefSimpleMenuModel : public ui::MenuModel {
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
CefRefPtr<CefMenuModel> CefMenuModel::CreateMenuModel(
|
||||
CefRefPtr<CefMenuModelDelegate> delegate) {
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
DCHECK(delegate);
|
||||
if (!delegate)
|
||||
return nullptr;
|
||||
|
||||
CefRefPtr<CefMenuModelImpl> menu_model =
|
||||
new CefMenuModelImpl(nullptr, delegate);
|
||||
return menu_model;
|
||||
}
|
||||
|
||||
struct CefMenuModelImpl::Item {
|
||||
Item(cef_menu_item_type_t type,
|
||||
@@ -203,9 +217,13 @@ struct CefMenuModelImpl::Item {
|
||||
};
|
||||
|
||||
|
||||
CefMenuModelImpl::CefMenuModelImpl(Delegate* delegate)
|
||||
CefMenuModelImpl::CefMenuModelImpl(
|
||||
Delegate* delegate,
|
||||
CefRefPtr<CefMenuModelDelegate> menu_model_delegate)
|
||||
: supported_thread_id_(base::PlatformThread::CurrentId()),
|
||||
delegate_(delegate) {
|
||||
delegate_(delegate),
|
||||
menu_model_delegate_(menu_model_delegate) {
|
||||
DCHECK(delegate_ || menu_model_delegate_);
|
||||
model_.reset(new CefSimpleMenuModel(this));
|
||||
}
|
||||
|
||||
@@ -266,7 +284,7 @@ CefRefPtr<CefMenuModel> CefMenuModelImpl::AddSubMenu(int command_id,
|
||||
return NULL;
|
||||
|
||||
Item item(MENUITEMTYPE_SUBMENU, command_id, label, -1);
|
||||
item.submenu_ = new CefMenuModelImpl(delegate_);
|
||||
item.submenu_ = new CefMenuModelImpl(delegate_, menu_model_delegate_);
|
||||
AppendItem(item);
|
||||
return item.submenu_.get();
|
||||
}
|
||||
@@ -313,7 +331,7 @@ CefRefPtr<CefMenuModel> CefMenuModelImpl::InsertSubMenuAt(
|
||||
return NULL;
|
||||
|
||||
Item item(MENUITEMTYPE_SUBMENU, command_id, label, -1);
|
||||
item.submenu_ = new CefMenuModelImpl(delegate_);
|
||||
item.submenu_ = new CefMenuModelImpl(delegate_, menu_model_delegate_);
|
||||
InsertItemAt(item, index);
|
||||
return item.submenu_.get();
|
||||
}
|
||||
@@ -618,13 +636,25 @@ bool CefMenuModelImpl::GetAcceleratorAt(int index, int& key_code,
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::ActivatedAt(int index, cef_event_flags_t event_flags) {
|
||||
if (VerifyContext() && delegate_)
|
||||
delegate_->ExecuteCommand(this, GetCommandIdAt(index), event_flags);
|
||||
if (!VerifyContext())
|
||||
return;
|
||||
|
||||
const int command_id = GetCommandIdAt(index);
|
||||
if (delegate_)
|
||||
delegate_->ExecuteCommand(this, command_id, event_flags);
|
||||
if (menu_model_delegate_)
|
||||
menu_model_delegate_->ExecuteCommand(this, command_id, event_flags);
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::MenuWillShow() {
|
||||
if (VerifyContext() && delegate_)
|
||||
if (!VerifyContext())
|
||||
return;
|
||||
|
||||
if (delegate_)
|
||||
delegate_->MenuWillShow(this);
|
||||
if (menu_model_delegate_)
|
||||
menu_model_delegate_->MenuWillShow(this);
|
||||
FOR_EACH_OBSERVER(Observer, observers_, MenuWillShow(this));
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::MenuClosed() {
|
||||
@@ -641,7 +671,13 @@ void CefMenuModelImpl::MenuClosed() {
|
||||
|
||||
base::string16 CefMenuModelImpl::GetFormattedLabelAt(int index) {
|
||||
base::string16 label = GetLabelAt(index).ToString16();
|
||||
delegate_->FormatLabel(label);
|
||||
if (delegate_)
|
||||
delegate_->FormatLabel(label);
|
||||
if (menu_model_delegate_) {
|
||||
CefString new_label = label;
|
||||
if (menu_model_delegate_->FormatLabel(this, new_label))
|
||||
label = new_label;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -662,6 +698,18 @@ bool CefMenuModelImpl::VerifyRefCount() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::AddObserver(Observer* observer) {
|
||||
observers_.AddObserver(observer);
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::RemoveObserver(Observer* observer) {
|
||||
observers_.RemoveObserver(observer);
|
||||
}
|
||||
|
||||
bool CefMenuModelImpl::HasObserver(Observer* observer) const {
|
||||
return observers_.HasObserver(observer);
|
||||
}
|
||||
|
||||
void CefMenuModelImpl::AddMenuItem(const content::MenuItem& menu_item) {
|
||||
const int command_id = static_cast<int>(menu_item.action);
|
||||
|
||||
@@ -726,6 +774,9 @@ void CefMenuModelImpl::ValidateItem(const Item& item) {
|
||||
void CefMenuModelImpl::OnMenuClosed() {
|
||||
if (delegate_)
|
||||
delegate_->MenuClosed(this);
|
||||
if (menu_model_delegate_)
|
||||
menu_model_delegate_->MenuClosed(this);
|
||||
FOR_EACH_OBSERVER(Observer, observers_, MenuClosed(this));
|
||||
}
|
||||
|
||||
bool CefMenuModelImpl::VerifyContext() {
|
||||
|
Reference in New Issue
Block a user