0

Give many PDFEngine::Client methods default implementations.

To make it possible to write a test client without having to write too
many empty implementations.

Change-Id: I45139957848a4d48e02740cc349605ab4b75e3a0
Reviewed-on: https://chromium-review.googlesource.com/1013997
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553781}
This commit is contained in:
Lei Zhang
2018-04-25 22:05:53 +00:00
committed by Commit Bot
parent 5bdf8f5736
commit e5de01b2d6
3 changed files with 28 additions and 44 deletions

@ -129,60 +129,60 @@ class PDFEngine {
virtual ~Client() {}
// Informs the client about the document's size in pixels.
virtual void DocumentSizeUpdated(const pp::Size& size) = 0;
virtual void DocumentSizeUpdated(const pp::Size& size) {}
// Informs the client that the given rect needs to be repainted.
virtual void Invalidate(const pp::Rect& rect) = 0;
virtual void Invalidate(const pp::Rect& rect) {}
// Informs the client to scroll the plugin area by the given offset.
virtual void DidScroll(const pp::Point& point) = 0;
virtual void DidScroll(const pp::Point& point) {}
// Scroll the horizontal/vertical scrollbars to a given position.
// Values are in screen coordinates, where 0 is the top/left of the document
// and a positive value is the distance in pixels from that line.
// For ScrollToY, setting |compensate_for_toolbar| will align the position
// with the bottom of the toolbar so the given position is always visible.
virtual void ScrollToX(int x_in_screen_coords) = 0;
virtual void ScrollToX(int x_in_screen_coords) {}
virtual void ScrollToY(int y_in_screen_coords,
bool compensate_for_toolbar) = 0;
bool compensate_for_toolbar) {}
// Scroll by a given delta relative to the current position.
virtual void ScrollBy(const pp::Point& point) = 0;
virtual void ScrollBy(const pp::Point& point) {}
// Scroll to zero-based |page|.
virtual void ScrollToPage(int page) = 0;
virtual void ScrollToPage(int page) {}
// Navigate to the given url.
virtual void NavigateTo(const std::string& url,
WindowOpenDisposition disposition) = 0;
WindowOpenDisposition disposition) {}
// Updates the cursor.
virtual void UpdateCursor(PP_CursorType_Dev cursor) = 0;
virtual void UpdateCursor(PP_CursorType_Dev cursor) {}
// Updates the tick marks in the vertical scrollbar.
virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) = 0;
virtual void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) {}
// Updates the number of find results for the current search term. If
// there are no matches 0 should be passed in. Only when the plugin has
// finished searching should it pass in the final count with final_result
// set to true.
virtual void NotifyNumberOfFindResultsChanged(int total,
bool final_result) = 0;
bool final_result) {}
// Updates the index of the currently selected search item.
virtual void NotifySelectedFindResultChanged(int current_find_index) = 0;
virtual void NotifySelectedFindResultChanged(int current_find_index) {}
// Notifies a page became visible.
virtual void NotifyPageBecameVisible(
const PDFEngine::PageFeatures* page_features) = 0;
const PDFEngine::PageFeatures* page_features) {}
// Prompts the user for a password to open this document. The callback is
// called when the password is retrieved.
virtual void GetDocumentPassword(
pp::CompletionCallbackWithOutput<pp::Var> callback) = 0;
pp::CompletionCallbackWithOutput<pp::Var> callback) {}
// Puts up an alert with the given message.
virtual void Alert(const std::string& message) = 0;
virtual void Alert(const std::string& message) {}
// Puts up a confirm with the given message, and returns true if the user
// presses OK, or false if they press cancel.
@ -201,24 +201,24 @@ class PDFEngine {
const std::string& cc,
const std::string& bcc,
const std::string& subject,
const std::string& body) = 0;
const std::string& body) {}
// Put up the print dialog.
virtual void Print() = 0;
virtual void Print() {}
// Submit the data using HTTP POST.
virtual void SubmitForm(const std::string& url,
const void* data,
int length) = 0;
int length) {}
// Creates and returns new URL loader for partial document requests.
virtual pp::URLLoader CreateURLLoader() = 0;
// Calls the client's OnCallback() function in |delay| with the given |id|.
virtual void ScheduleCallback(int id, base::TimeDelta delay) = 0;
virtual void ScheduleCallback(int id, base::TimeDelta delay) {}
// Calls the client's OnTouchTimerCallback() function in |delay| with the
// given |id|.
virtual void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) = 0;
virtual void ScheduleTouchTimerCallback(int id, base::TimeDelta delay) {}
// Searches the given string for "term" and returns the results. Unicode-
// aware.
@ -232,29 +232,28 @@ class PDFEngine {
bool case_sensitive) = 0;
// Notifies the client that the engine has painted a page from the document.
virtual void DocumentPaintOccurred() = 0;
virtual void DocumentPaintOccurred() {}
// Notifies the client that the document has finished loading.
virtual void DocumentLoadComplete(const DocumentFeatures& document_features,
uint32_t file_size) = 0;
uint32_t file_size) {}
// Notifies the client that the document has failed to load.
virtual void DocumentLoadFailed() = 0;
virtual void DocumentLoadFailed() {}
// Notifies the client that the document has requested substitute fonts.
virtual void FontSubstituted() = 0;
virtual void FontSubstituted() {}
virtual pp::Instance* GetPluginInstance() = 0;
// Notifies that an unsupported feature in the PDF was encountered.
virtual void DocumentHasUnsupportedFeature(const std::string& feature) = 0;
virtual void DocumentHasUnsupportedFeature(const std::string& feature) {}
// Notifies the client about document load progress.
virtual void DocumentLoadProgress(uint32_t available,
uint32_t doc_size) = 0;
virtual void DocumentLoadProgress(uint32_t available, uint32_t doc_size) {}
// Notifies the client about focus changes for form text fields.
virtual void FormTextFieldFocusChange(bool in_focus) = 0;
virtual void FormTextFieldFocusChange(bool in_focus) {}
// Returns true if the plugin has been opened within print preview.
virtual bool IsPrintPreview() = 0;
@ -263,7 +262,7 @@ class PDFEngine {
virtual uint32_t GetBackgroundColor() = 0;
// Cancel browser initiated document download.
virtual void CancelBrowserDownload() = 0;
virtual void CancelBrowserDownload() {}
// Sets selection status.
virtual void IsSelectingChanged(bool is_selecting) {}

@ -12,8 +12,6 @@ namespace chrome_pdf {
PreviewModeClient::PreviewModeClient(Client* client) : client_(client) {}
void PreviewModeClient::DocumentSizeUpdated(const pp::Size& size) {}
void PreviewModeClient::Invalidate(const pp::Rect& rect) {
NOTREACHED();
}
@ -63,9 +61,6 @@ void PreviewModeClient::NotifySelectedFindResultChanged(
NOTREACHED();
}
void PreviewModeClient::NotifyPageBecameVisible(
const PDFEngine::PageFeatures* page_features) {}
void PreviewModeClient::GetDocumentPassword(
pp::CompletionCallbackWithOutput<pp::Var> callback) {
callback.Run(PP_ERROR_FAILED);
@ -158,9 +153,6 @@ void PreviewModeClient::FontSubstituted() {
NOTREACHED();
}
void PreviewModeClient::DocumentLoadProgress(uint32_t available,
uint32_t doc_size) {}
void PreviewModeClient::FormTextFieldFocusChange(bool in_focus) {
NOTREACHED();
}
@ -170,8 +162,6 @@ bool PreviewModeClient::IsPrintPreview() {
return false;
}
void PreviewModeClient::CancelBrowserDownload() {}
float PreviewModeClient::GetToolbarHeightInScreenCoords() {
return 0.0f;
}

@ -27,7 +27,6 @@ class PreviewModeClient : public PDFEngine::Client {
~PreviewModeClient() override {}
// PDFEngine::Client implementation.
void DocumentSizeUpdated(const pp::Size& size) override;
void Invalidate(const pp::Rect& rect) override;
void DidScroll(const pp::Point& point) override;
void ScrollToX(int x_in_screen_coords) override;
@ -40,8 +39,6 @@ class PreviewModeClient : public PDFEngine::Client {
void UpdateTickMarks(const std::vector<pp::Rect>& tickmarks) override;
void NotifyNumberOfFindResultsChanged(int total, bool final_result) override;
void NotifySelectedFindResultChanged(int current_find_index) override;
void NotifyPageBecameVisible(
const PDFEngine::PageFeatures* page_features) override;
void GetDocumentPassword(
pp::CompletionCallbackWithOutput<pp::Var> callback) override;
void Alert(const std::string& message) override;
@ -72,10 +69,8 @@ class PreviewModeClient : public PDFEngine::Client {
void FontSubstituted() override;
pp::Instance* GetPluginInstance() override;
void DocumentHasUnsupportedFeature(const std::string& feature) override;
void DocumentLoadProgress(uint32_t available, uint32_t doc_size) override;
void FormTextFieldFocusChange(bool in_focus) override;
bool IsPrintPreview() override;
void CancelBrowserDownload() override;
float GetToolbarHeightInScreenCoords() override;
uint32_t GetBackgroundColor() override;