Chromium Code Reviews| 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 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 2703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2714 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { | 2714 PDFiumEngine::SelectionChangeInvalidator::~SelectionChangeInvalidator() { |
| 2715 // Offset the old selections if the document scrolled since we recorded them. | 2715 // Offset the old selections if the document scrolled since we recorded them. |
| 2716 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); | 2716 pp::Point offset = previous_origin_ - engine_->GetVisibleRect().point(); |
| 2717 for (size_t i = 0; i < old_selections_.size(); ++i) | 2717 for (size_t i = 0; i < old_selections_.size(); ++i) |
| 2718 old_selections_[i].Offset(offset); | 2718 old_selections_[i].Offset(offset); |
| 2719 | 2719 |
| 2720 std::vector<pp::Rect> new_selections; | 2720 std::vector<pp::Rect> new_selections; |
| 2721 GetVisibleSelectionsScreenRects(&new_selections); | 2721 GetVisibleSelectionsScreenRects(&new_selections); |
| 2722 for (size_t i = 0; i < new_selections.size(); ++i) { | 2722 for (size_t i = 0; i < new_selections.size(); ++i) { |
| 2723 for (size_t j = 0; j < old_selections_.size(); ++j) { | 2723 for (size_t j = 0; j < old_selections_.size(); ++j) { |
| 2724 if (new_selections[i] == old_selections_[j]) { | 2724 if (!old_selections_[j].IsEmpty() && |
| 2725 new_selections[i] == old_selections_[j]) { | |
| 2725 // Rectangle was selected before and after, so no need to invalidate it. | 2726 // Rectangle was selected before and after, so no need to invalidate it. |
| 2726 // Mark the rectangles by setting them to empty. | 2727 // Mark the rectangles by setting them to empty. |
| 2727 new_selections[i] = old_selections_[j] = pp::Rect(); | 2728 new_selections[i] = old_selections_[j] = pp::Rect(); |
| 2729 break; | |
|
raymes
2014/09/29 01:09:51
I don't think we can early return from this loop (
Deepak
2014/09/29 02:41:28
@raymes, When below condition
new_selections[i] =
raymes
2014/09/29 03:08:16
Oh I see! Is it ever possible for old_selections_
Deepak
2014/09/29 03:19:52
I think old selection does not contain duplicates.
| |
| 2728 } | 2730 } |
| 2729 } | 2731 } |
| 2730 } | 2732 } |
| 2731 | 2733 |
| 2732 for (size_t i = 0; i < old_selections_.size(); ++i) { | 2734 for (size_t i = 0; i < old_selections_.size(); ++i) { |
| 2733 if (!old_selections_[i].IsEmpty()) | 2735 if (!old_selections_[i].IsEmpty()) |
| 2734 engine_->client_->Invalidate(old_selections_[i]); | 2736 engine_->client_->Invalidate(old_selections_[i]); |
| 2735 } | 2737 } |
| 2736 for (size_t i = 0; i < new_selections.size(); ++i) { | 2738 for (size_t i = 0; i < new_selections.size(); ++i) { |
| 2737 if (!new_selections[i].IsEmpty()) | 2739 if (!new_selections[i].IsEmpty()) |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3518 double* height) { | 3520 double* height) { |
| 3519 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3521 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3520 if (!doc) | 3522 if (!doc) |
| 3521 return false; | 3523 return false; |
| 3522 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3524 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3523 FPDF_CloseDocument(doc); | 3525 FPDF_CloseDocument(doc); |
| 3524 return success; | 3526 return success; |
| 3525 } | 3527 } |
| 3526 | 3528 |
| 3527 } // namespace chrome_pdf | 3529 } // namespace chrome_pdf |
| OLD | NEW |