cef/libcef/browser/image_impl.h

124 lines
5.1 KiB
C
Raw Normal View History

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-01-19 21:09:01 +01:00
// 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_LIBCEF_BROWSER_IMAGE_IMPL_H_
#define CEF_LIBCEF_BROWSER_IMAGE_IMPL_H_
#pragma once
#include "include/cef_image.h"
#include "libcef/browser/thread_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
class CefImageImpl : public CefImage {
public:
// Creates an empty image with no representations.
CefImageImpl();
// Creates a new image by copying the ImageSkia for use as the default
// representation.
explicit CefImageImpl(const gfx::ImageSkia& image_skia);
// Deletes the image and, if the only owner of the storage, all of its cached
// representations.
~CefImageImpl() override;
// CefImage methods:
bool IsEmpty() override;
bool IsSame(CefRefPtr<CefImage> that) override;
bool AddBitmap(float scale_factor,
int pixel_width,
int pixel_height,
cef_color_type_t color_type,
cef_alpha_type_t alpha_type,
const void* pixel_data,
size_t pixel_data_size) override;
bool AddPNG(float scale_factor,
const void* png_data,
size_t png_data_size) override;
bool AddJPEG(float scale_factor,
const void* jpeg_data,
size_t jpeg_data_size) override;
size_t GetWidth() override;
size_t GetHeight() override;
bool HasRepresentation(float scale_factor) override;
bool RemoveRepresentation(float scale_factor) override;
bool GetRepresentationInfo(float scale_factor,
float& actual_scale_factor,
int& pixel_width,
int& pixel_height) override;
CefRefPtr<CefBinaryValue> GetAsBitmap(float scale_factor,
cef_color_type_t color_type,
cef_alpha_type_t alpha_type,
int& pixel_width,
int& pixel_height) override;
CefRefPtr<CefBinaryValue> GetAsPNG(float scale_factor,
bool with_transparency,
int& pixel_width,
int& pixel_height) override;
CefRefPtr<CefBinaryValue> GetAsJPEG(float scale_factor,
int quality,
int& pixel_width,
int& pixel_height) override;
// Add |bitmaps| which should be the same image at different scale factors.
// |scale_1x_size| is the size in pixels of the 1x factor image. If
// |scale_1x_size| is 0 the smallest image size in pixels will be used as the
// 1x factor size.
void AddBitmaps(int32_t scale_1x_size, const std::vector<SkBitmap>& bitmaps);
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-01-19 21:09:01 +01:00
// Return a representation of this Image that contains only the bitmap nearest
// |scale_factor| as the 1x scale representation. Conceptually this is an
// incorrect representation but is necessary to work around bugs in the views
// architecture.
// TODO(cef): Remove once https://crbug.com/597732 is resolved.
gfx::ImageSkia GetForced1xScaleRepresentation(float scale_factor) const;
const gfx::Image& image() const { return image_; }
private:
// Add a bitmap.
bool AddBitmap(float scale_factor, const SkBitmap& bitmap);
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-01-19 21:09:01 +01:00
// Returns the bitmap that most closely matches |scale_factor| or nullptr if
// one doesn't exist.
const SkBitmap* GetBitmap(float scale_factor) const;
// Convert |src_bitmap| to |target_bitmap| with |target_ct| and |target_at|.
static bool ConvertBitmap(const SkBitmap& src_bitmap,
SkBitmap* target_bitmap,
SkColorType target_ct,
SkAlphaType target_at);
// The |bitmap| argument will be RGBA or BGRA and either opaque or transparent
// with post-multiplied alpha. Writes the compressed output into |compressed|.
typedef base::Callback<bool(const SkBitmap& /*bitmap*/,
std::vector<unsigned char>* /*compressed*/)>
CompressionMethod;
// Write |bitmap| into |compressed| using |method|.
static bool WriteCompressedFormat(const SkBitmap& bitmap,
std::vector<unsigned char>* compressed,
const CompressionMethod& method);
// Write |bitmap| into |compressed| using PNG encoding.
static bool WritePNG(const SkBitmap& bitmap,
std::vector<unsigned char>* compressed,
bool with_transparency);
// Write |bitmap| into |compressed| using JPEG encoding. The alpha channel
// will be ignored.
static bool WriteJPEG(const SkBitmap& bitmap,
std::vector<unsigned char>* compressed,
int quality);
gfx::Image image_;
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefImageImpl);
DISALLOW_COPY_AND_ASSIGN(CefImageImpl);
};
#endif // CEF_LIBCEF_BROWSER_IMAGE_IMPL_H_