cef/tests/cefclient/browser/views_window.h
Marshall Greenblatt 06e73fff15 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.
2016-04-26 11:58:13 -04:00

157 lines
5.2 KiB
C++

// Copyright (c) 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.
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_
#pragma once
#include <string>
#include "include/cef_menu_model_delegate.h"
#include "include/views/cef_button_delegate.h"
#include "include/views/cef_browser_view.h"
#include "include/views/cef_browser_view_delegate.h"
#include "include/views/cef_label_button.h"
#include "include/views/cef_menu_button.h"
#include "include/views/cef_menu_button_delegate.h"
#include "include/views/cef_textfield.h"
#include "include/views/cef_textfield_delegate.h"
#include "include/views/cef_window.h"
#include "include/views/cef_window_delegate.h"
namespace client {
// Implements a CefWindow that hosts a single CefBrowserView and optional
// Views-based controls. All methods must be called on the browser process UI
// thread.
class ViewsWindow : public CefBrowserViewDelegate,
public CefMenuButtonDelegate,
public CefMenuModelDelegate,
public CefTextfieldDelegate,
public CefWindowDelegate {
public:
// Delegate methods will be called on the browser process UI thread.
class Delegate {
public:
// Return true if the window should show controls.
virtual bool WithControls() =0;
// Return the initial window bounds.
virtual CefRect GetWindowBounds() =0;
// Called when the ViewsWindow is created.
virtual void OnViewsWindowCreated(CefRefPtr<ViewsWindow> window) =0;
// Called when the ViewsWindow is destroyed. All references to |window|
// should be released in this callback.
virtual void OnViewsWindowDestroyed(CefRefPtr<ViewsWindow> window) =0;
// Return the Delegate for the popup window controlled by |client|.
virtual Delegate* GetDelegateForPopup(CefRefPtr<CefClient> client) =0;
// Called to execute a test. See resource.h for |test_id| values.
virtual void OnTest(int test_id) = 0;
// Called to exit the application.
virtual void OnExit() = 0;
protected:
virtual ~Delegate() {}
};
// Create a new top-level ViewsWindow hosting a browser with the specified
// configuration.
static CefRefPtr<ViewsWindow> Create(
Delegate* delegate,
CefRefPtr<CefClient> client,
const CefString& url,
const CefBrowserSettings& settings,
CefRefPtr<CefRequestContext> request_context);
void Show();
void Hide();
void Minimize();
void Maximize();
void SetBounds(const CefRect& bounds);
void Close(bool force);
void SetAddress(const std::string& url);
void SetTitle(const std::string& title);
void SetFavicon(CefRefPtr<CefImage> image);
void SetFullscreen(bool fullscreen);
void SetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward);
void SetDraggableRegions(const std::vector<CefDraggableRegion>& regions);
// CefBrowserViewDelegate methods:
bool OnPopupBrowserViewCreated(
CefRefPtr<CefBrowserView> browser_view,
CefRefPtr<CefBrowserView> popup_browser_view,
bool is_devtools) OVERRIDE;
// CefButtonDelegate methods:
void OnButtonPressed(CefRefPtr<CefButton> button) OVERRIDE;
// CefMenuButtonDelegate methods:
void OnMenuButtonPressed(CefRefPtr<CefMenuButton> menu_button,
const CefPoint& screen_point) OVERRIDE;
// CefMenuModelDelegate methods:
void ExecuteCommand(CefRefPtr<CefMenuModel> menu_model,
int command_id,
cef_event_flags_t event_flags) OVERRIDE;
// CefTextfieldDelegate methods:
bool OnKeyEvent(CefRefPtr<CefTextfield> textfield,
const CefKeyEvent& event) OVERRIDE;
// CefWindowDelegate methods:
void OnWindowCreated(CefRefPtr<CefWindow> window) OVERRIDE;
void OnWindowDestroyed(CefRefPtr<CefWindow> window) OVERRIDE;
bool IsFrameless(CefRefPtr<CefWindow> window) OVERRIDE;
bool CanClose(CefRefPtr<CefWindow> window) OVERRIDE;
// CefViewDelegate methods:
CefSize GetMinimumSize(CefRefPtr<CefView> view) override;
private:
// |delegate| is guaranteed to outlive this object.
// |browser_view| may be NULL, in which case SetBrowserView() will be called.
ViewsWindow(Delegate* delegate,
CefRefPtr<CefBrowserView> browser_view);
void SetBrowserView(CefRefPtr<CefBrowserView> browser_view);
// Create controls.
void CreateMenuModel();
CefRefPtr<CefLabelButton> CreateBrowseButton(const std::string& label,
int id);
// Add controls to the Window.
void AddControls();
// Enable or disable a view by |id|.
void EnableView(int id, bool enable);
// Show/hide top controls on the Window.
void ShowTopControls(bool show);
Delegate* delegate_; // Not owned by this object.
CefRefPtr<CefBrowserView> browser_view_;
bool frameless_;
bool with_controls_;
CefRefPtr<CefWindow> window_;
CefRefPtr<CefMenuModel> menu_model_;
CefSize minimum_window_size_;
IMPLEMENT_REFCOUNTING(ViewsWindow);
DISALLOW_COPY_AND_ASSIGN(ViewsWindow);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_