OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 3248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3259 // This is our highlight color. | 3259 // This is our highlight color. |
3260 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); | 3260 pixel[0] = static_cast<uint8_t>(pixel[0] * (kHighlightColorB / 255.0)); |
3261 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); | 3261 pixel[1] = static_cast<uint8_t>(pixel[1] * (kHighlightColorG / 255.0)); |
3262 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); | 3262 pixel[2] = static_cast<uint8_t>(pixel[2] * (kHighlightColorR / 255.0)); |
3263 } | 3263 } |
3264 } | 3264 } |
3265 } | 3265 } |
3266 | 3266 |
3267 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( | 3267 PDFiumEngine::SelectionChangeInvalidator::SelectionChangeInvalidator( |
3268 PDFiumEngine* engine) | 3268 PDFiumEngine* engine) |
3269 : engine_(engine) { | 3269 : engine_(engine), |
3270 previous_origin_ = engine_->GetVisibleRect().point(); | 3270 previous_origin_(engine_->GetVisibleRect().point()), |
3271 GetVisibleSelectionsScreenRects(&old_selections_); | 3271 old_selections_(GetVisibleSelections()) {} |
3272 } | |
3273 | 3272 |
3274 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { | 3273 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { |
3275 // Offset the old selections if the document scrolled since we recorded them. | 3274 // Offset the old selections if the document scrolled since we recorded them. |
3276 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); | 3275 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); |
3277 for (auto& old_selection : old_selections_) | 3276 for (auto& old_selection : old_selections_) |
3278 old_selection.Offset(offset); | 3277 old_selection.Offset(offset); |
3279 | 3278 |
3280 std::vector<pp::Rect> new_selections; | 3279 std::vector<pp::Rect> new_selections = GetVisibleSelections(); |
3281 GetVisibleSelectionsScreenRects(&new_selections); | |
3282 for (auto& new_selection : new_selections) { | 3280 for (auto& new_selection : new_selections) { |
3283 for (auto& old_selection : old_selections_) { | 3281 for (auto& old_selection : old_selections_) { |
3284 if (!old_selection.IsEmpty() && new_selection == old_selection) { | 3282 if (!old_selection.IsEmpty() && new_selection == old_selection) { |
3285 // Rectangle was selected before and after, so no need to invalidate it. | 3283 // Rectangle was selected before and after, so no need to invalidate it. |
3286 // Mark the rectangles by setting them to empty. | 3284 // Mark the rectangles by setting them to empty. |
3287 new_selection = old_selection = pp::Rect(); | 3285 new_selection = old_selection = pp::Rect(); |
3288 break; | 3286 break; |
3289 } | 3287 } |
3290 } | 3288 } |
3291 } | 3289 } |
3292 | 3290 |
3293 bool selection_changed = false; | 3291 bool selection_changed = false; |
3294 for (const auto& old_selection : old_selections_) { | 3292 for (const auto& old_selection : old_selections_) { |
3295 if (!old_selection.IsEmpty()) { | 3293 if (!old_selection.IsEmpty()) { |
3296 engine_->client_->Invalidate(old_selection); | 3294 engine_->client_->Invalidate(old_selection); |
3297 selection_changed = true; | 3295 selection_changed = true; |
3298 } | 3296 } |
3299 } | 3297 } |
3300 for (const auto& new_selection : new_selections) { | 3298 for (const auto& new_selection : new_selections) { |
3301 if (!new_selection.IsEmpty()) { | 3299 if (!new_selection.IsEmpty()) { |
3302 engine_->client_->Invalidate(new_selection); | 3300 engine_->client_->Invalidate(new_selection); |
3303 selection_changed = true; | 3301 selection_changed = true; |
3304 } | 3302 } |
3305 } | 3303 } |
3306 if (selection_changed) | 3304 if (selection_changed) |
3307 engine_->OnSelectionChanged(); | 3305 engine_->OnSelectionChanged(); |
3308 } | 3306 } |
3309 | 3307 |
3310 void PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelectionsScreenRects( | 3308 std::vector<pp::Rect> |
3311 std::vector<pp::Rect>* rects) { | 3309 PDFiumEngine::SelectionChangeInvalidator::GetVisibleSelections() const { |
3312 pp::Rect visible_rect = engine_->GetVisibleRect(); | 3310 std::vector<pp::Rect> rects; |
| 3311 pp::Point visible_point = engine_->GetVisibleRect().point(); |
3313 for (auto& range : engine_->selection_) { | 3312 for (auto& range : engine_->selection_) { |
3314 int page_index = range.page_index(); | 3313 // Exclude selections on pages that's not currently visible. |
3315 if (!engine_->IsPageVisible(page_index)) | 3314 if (!engine_->IsPageVisible(range.page_index())) |
3316 continue; // This selection is on a page that's not currently visible. | 3315 continue; |
3317 | 3316 |
3318 std::vector<pp::Rect> selection_rects = | 3317 std::vector<pp::Rect> selection_rects = range.GetScreenRects( |
3319 range.GetScreenRects(visible_rect.point(), engine_->current_zoom_, | 3318 visible_point, engine_->current_zoom_, engine_->current_rotation_); |
3320 engine_->current_rotation_); | 3319 rects.insert(rects.end(), selection_rects.begin(), selection_rects.end()); |
3321 rects->insert(rects->end(), selection_rects.begin(), selection_rects.end()); | |
3322 } | 3320 } |
| 3321 return rects; |
3323 } | 3322 } |
3324 | 3323 |
3325 PDFiumEngine::MouseDownState::MouseDownState( | 3324 PDFiumEngine::MouseDownState::MouseDownState( |
3326 const PDFiumPage::Area& area, | 3325 const PDFiumPage::Area& area, |
3327 const PDFiumPage::LinkTarget& target) | 3326 const PDFiumPage::LinkTarget& target) |
3328 : area_(area), target_(target) {} | 3327 : area_(area), target_(target) {} |
3329 | 3328 |
3330 PDFiumEngine::MouseDownState::~MouseDownState() {} | 3329 PDFiumEngine::MouseDownState::~MouseDownState() {} |
3331 | 3330 |
3332 void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area, | 3331 void PDFiumEngine::MouseDownState::Set(const PDFiumPage::Area& area, |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4192 FPDF_DOCUMENT doc = | 4191 FPDF_DOCUMENT doc = |
4193 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); | 4192 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); |
4194 if (!doc) | 4193 if (!doc) |
4195 return false; | 4194 return false; |
4196 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 4195 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
4197 FPDF_CloseDocument(doc); | 4196 FPDF_CloseDocument(doc); |
4198 return success; | 4197 return success; |
4199 } | 4198 } |
4200 | 4199 |
4201 } // namespace chrome_pdf | 4200 } // namespace chrome_pdf |
OLD | NEW |