Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "web/cef_handler.h"
- #include <sstream>
- #include <string>
- #include "include/base/cef_bind.h"
- #include "include/cef_app.h"
- #include "include/views/cef_browser_view.h"
- #include "include/views/cef_window.h"
- #include "include/wrapper/cef_closure_task.h"
- #include "include/wrapper/cef_helpers.h"
- #include "console/console.h"
- GFX_ImplementTextureProfile(GFXWebTextureProfile,
- GFXTextureProfile::DiffuseMap,
- GFXTextureProfile::NoMipmap | GFXTextureProfile::Dynamic,
- GFXTextureProfile::NONE);
- namespace {
- CefHandler* g_instance = NULL;
- } // namespace
- CefHandler::CefHandler()
- : is_closing_(false) {
- DCHECK(!g_instance);
- g_instance = this;
- }
- CefHandler::~CefHandler() {
- g_instance = NULL;
- mTextureObject.free();
- }
- // static
- CefHandler* CefHandler::GetInstance() {
- return g_instance;
- }
- void CefHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
- const CefString& title) {
- CEF_REQUIRE_UI_THREAD();
- // Set the title of the window using platform APIs.
- PlatformTitleChange(browser, title);
- }
- void CefHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
- CEF_REQUIRE_UI_THREAD();
- // Create texture to write to
- mTextureObject.set(mTextureSize, mTextureSize, GFXFormatR8G8B8X8, &GFXWebTextureProfile, avar("%s() - (line %d)", __FUNCTION__, __LINE__), 0);
- // Add to the list of existing browsers.
- browser_list_.push_back(browser);
- }
- bool CefHandler::DoClose(CefRefPtr<CefBrowser> browser) {
- CEF_REQUIRE_UI_THREAD();
- // Closing the main window requires special handling. See the DoClose()
- // documentation in the CEF header for a detailed destription of this
- // process.
- if (browser_list_.size() == 1) {
- // Set a flag to indicate that the window close should be allowed.
- is_closing_ = true;
- }
- // Allow the close. For windowed browsers this will result in the OS close
- // event being sent.
- return false;
- }
- void CefHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
- CEF_REQUIRE_UI_THREAD();
- // Remove from the list of existing browsers.
- BrowserList::iterator bit = browser_list_.begin();
- for (; bit != browser_list_.end(); ++bit) {
- if ((*bit)->IsSame(browser)) {
- browser_list_.erase(bit);
- break;
- }
- }
- if (browser_list_.empty()) {
- // All browser windows have closed. Quit the application message loop.
- CefQuitMessageLoop();
- }
- }
- void CefHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
- CefRefPtr<CefFrame> frame,
- ErrorCode errorCode,
- const CefString& errorText,
- const CefString& failedUrl) {
- CEF_REQUIRE_UI_THREAD();
- // Don't display an error for downloaded files.
- if (errorCode == ERR_ABORTED)
- return;
- // Display a load error message.
- std::stringstream ss;
- ss << "<html><body bgcolor=\"white\">"
- "<h2>Failed to load URL "
- << std::string(failedUrl) << " with error " << std::string(errorText)
- << " (" << errorCode << ").</h2></body></html>";
- frame->LoadString(ss.str(), failedUrl);
- }
- void CefHandler::CloseAllBrowsers(bool force_close) {
- if (!CefCurrentlyOn(TID_UI)) {
- // Execute on the UI thread.
- CefPostTask(TID_UI, base::Bind(&CefHandler::CloseAllBrowsers, this,
- force_close));
- return;
- }
- if (browser_list_.empty())
- return;
- BrowserList::const_iterator it = browser_list_.begin();
- for (; it != browser_list_.end(); ++it)
- (*it)->GetHost()->CloseBrowser(force_close);
- }
- //---------------------------------------------------------------------------------------------------------------
- // CefRenderHandler methods, see http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderHandler.html
- // Called to retrieve the root window rectangle in screen coordinates. Return true if the rectangle was provided.
- bool CefHandler::GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
- Con::printf("!!! GetRootScreenRect");
- rect = CefRect(0, 0, mTextureSize, mTextureSize);
- return true;
- }
- // Called to retrieve the view rectangle which is relative to screen coordinates. Return true if the rectangle was provided.
- bool CefHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
- Con::printf("!!! GetViewRect");
- rect = CefRect(0, 0, mTextureSize, mTextureSize);
- return true;
- }
- // Called to retrieve the translation from view coordinates to actual screen coordinates. Return true if the screen coordinates were provided.
- bool CefHandler::GetScreenPoint(CefRefPtr<CefBrowser> browser, int viewX, int viewY, int& screenX, int& screenY) {
- Con::printf("!!! GetScreenPoint");
- return false;
- }
- // Called to allow the client to fill in the CefScreenInfo object with appropriate values. Return true if the |screen_info| structure has been modified.
- // If the screen info rectangle is left empty the rectangle from GetViewRect will be used. If the rectangle is still empty or invalid popups may not be drawn correctly.
- bool CefHandler::GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info) {
- Con::printf("!!! GetScreenInfo");
- return false;
- }
- // Called when the browser wants to show or hide the popup widget. The popup should be shown if |show| is true and hidden if |show| is false.
- void CefHandler::OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {
- Con::printf("!!! OnPopupShow");
- }
- // Called when the browser wants to move or resize the popup widget. |rect| contains the new location and size in view coordinates.
- void CefHandler::OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) {
- Con::printf("!!! OnPopupSize");
- }
- // Called when an element should be painted. Pixel values passed to this method are scaled relative to view coordinates based on the value of CefScreenInfo.device_scale_factor
- // returned from GetScreenInfo.
- // |type| indicates whether the element is the view or the popup widget.
- // |buffer| contains the pixel data for the whole image.
- // |dirtyRects| contains the set of rectangles in pixel coordinates that need to be repainted.
- // |buffer| will be |width|*|height|*4 bytes in size and represents a BGRA image with an upper-left origin.
- void CefHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) {
- Con::printf("!!! OnPaint");
- }
- // Called when the browser's cursor has changed. If |type| is CT_CUSTOM then |custom_cursor_info| will be populated with the custom cursor information.
- void CefHandler::OnCursorChange(CefRefPtr<CefBrowser> browser, CefCursorHandle cursor, CefRenderHandler::CursorType type, const CefCursorInfo& custom_cursor_info) {
- Con::printf("!!! OnCursorChange");
- }
- // Called when the user starts dragging content in the web view. Contextual information about the dragged content is supplied by |drag_data|.
- // (|x|, |y|) is the drag start location in screen coordinates. OS APIs that run a system message loop may be used within the StartDragging call.
- // Return false to abort the drag operation. Don't call any of CefBrowserHost::DragSource*Ended* methods after returning false.
- // Return true to handle the drag operation.
- // Call CefBrowserHost::DragSourceEndedAt and DragSourceSystemDragEnded either synchronously or asynchronously to inform the web view that the drag operation has ended.
- bool CefHandler::StartDragging(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDragData> drag_data, CefRenderHandler::DragOperationsMask allowed_ops, int x, int y) {
- Con::printf("!!! StartDragging");
- return false;
- }
- // Called when the web view wants to update the mouse cursor during a drag & drop operation. |operation| describes the allowed operation (none, move, copy, link).
- void CefHandler::UpdateDragCursor(CefRefPtr<CefBrowser> browser, CefRenderHandler::DragOperation operation) {
- Con::printf("!!! UpdateDragCursor");
- }
- // Called when the IME composition range has changed. |selected_range| is the range of characters that have been selected. |character_bounds| is the bounds of each character in view coordinates.
- void CefHandler::OnImeCompositionRangeChanged(CefRefPtr<CefBrowser> browser, const CefRange& selection_range, const CefRenderHandler::RectList& character_bounds) {
- Con::printf("!!! OnImeCompositionRangeChanged");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement