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 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1598 if (progressive_paints_[i].page_index == page) | 1598 if (progressive_paints_[i].page_index == page) |
1599 return PDFiumPage::NONSELECTABLE_AREA; | 1599 return PDFiumPage::NONSELECTABLE_AREA; |
1600 } | 1600 } |
1601 | 1601 |
1602 *page_index = page; | 1602 *page_index = page; |
1603 return pages_[page]->GetCharIndex(point, current_rotation_, char_index, | 1603 return pages_[page]->GetCharIndex(point, current_rotation_, char_index, |
1604 target); | 1604 target); |
1605 } | 1605 } |
1606 | 1606 |
1607 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { | 1607 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
1608 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) | 1608 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) { |
gene
2015/01/06 18:40:04
We probably don't want to erase selection for midd
Deepak
2015/01/07 04:59:01
Done.
| |
1609 return false; | 1609 if (!selection_.size()) |
1610 return false; | |
1611 pp::Rect selection_rect; | |
1612 std::vector<pp::Rect> selection_rect_vector; | |
1613 GetAllScreenRectsUnion(selection_, GetVisibleRect().point(), | |
1614 selection_rect_vector); | |
1615 for (size_t i = 0; i < selection_rect_vector.size(); ++i) | |
1616 selection_rect = selection_rect.Union(selection_rect_vector[i]); | |
gene
2015/01/06 18:40:04
Why do you want to unite all rects, instead of tes
Deepak
2015/01/07 04:59:01
I agree with you. This will help us in early retur
| |
1617 | |
1618 pp::Point point = event.GetPosition(); | |
1619 if (selection_rect.IsEmpty() || | |
1620 selection_rect.Contains(point.x(), point.y())) | |
1621 return false; | |
1622 SelectionChangeInvalidator selection_invalidator(this); | |
1623 selection_.clear(); | |
1624 return true; | |
1625 } | |
1610 | 1626 |
1611 SelectionChangeInvalidator selection_invalidator(this); | 1627 SelectionChangeInvalidator selection_invalidator(this); |
1612 selection_.clear(); | 1628 selection_.clear(); |
1613 | 1629 |
1614 int page_index = -1; | 1630 int page_index = -1; |
1615 int char_index = -1; | 1631 int char_index = -1; |
1616 PDFiumPage::LinkTarget target; | 1632 PDFiumPage::LinkTarget target; |
1617 PDFiumPage::Area area = GetCharIndex(event, &page_index, | 1633 PDFiumPage::Area area = GetCharIndex(event, &page_index, |
1618 &char_index, &target); | 1634 &char_index, &target); |
1619 mouse_down_state_.Set(area, target); | 1635 mouse_down_state_.Set(area, target); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2171 find_results_.clear(); | 2187 find_results_.clear(); |
2172 next_page_to_search_ = -1; | 2188 next_page_to_search_ = -1; |
2173 last_page_to_search_ = -1; | 2189 last_page_to_search_ = -1; |
2174 last_character_index_to_search_ = -1; | 2190 last_character_index_to_search_ = -1; |
2175 current_find_index_.Invalidate(); | 2191 current_find_index_.Invalidate(); |
2176 current_find_text_.clear(); | 2192 current_find_text_.clear(); |
2177 UpdateTickMarks(); | 2193 UpdateTickMarks(); |
2178 find_factory_.CancelAll(); | 2194 find_factory_.CancelAll(); |
2179 } | 2195 } |
2180 | 2196 |
2197 void PDFiumEngine::GetAllScreenRectsUnion(std::vector<PDFiumRange> rect_range, | |
2198 const pp::Point offset_point, | |
2199 std::vector<pp::Rect>& rect_vector) { | |
2200 for (size_t i = 0; i < rect_range.size(); ++i) { | |
2201 pp::Rect rect; | |
2202 std::vector<pp::Rect> rects = rect_range[i].GetScreenRects( | |
2203 offset_point, current_zoom_, current_rotation_); | |
2204 for (size_t j = 0; j < rects.size(); ++j) | |
2205 rect = rect.Union(rects[j]); | |
2206 rect_vector.push_back(rect); | |
2207 } | |
2208 } | |
2209 | |
2181 void PDFiumEngine::UpdateTickMarks() { | 2210 void PDFiumEngine::UpdateTickMarks() { |
2182 std::vector<pp::Rect> tickmarks; | 2211 std::vector<pp::Rect> tickmarks; |
2183 for (size_t i = 0; i < find_results_.size(); ++i) { | 2212 GetAllScreenRectsUnion(find_results_, pp::Point(0, 0), tickmarks); |
2184 pp::Rect rect; | |
2185 // Always use an origin of 0,0 since scroll positions don't affect tickmark. | |
2186 std::vector<pp::Rect> rects = find_results_[i].GetScreenRects( | |
2187 pp::Point(0, 0), current_zoom_, current_rotation_); | |
2188 for (size_t j = 0; j < rects.size(); ++j) | |
2189 rect = rect.Union(rects[j]); | |
2190 tickmarks.push_back(rect); | |
2191 } | |
2192 | |
2193 client_->UpdateTickMarks(tickmarks); | 2213 client_->UpdateTickMarks(tickmarks); |
2194 } | 2214 } |
2195 | 2215 |
2196 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { | 2216 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { |
2197 CancelPaints(); | 2217 CancelPaints(); |
2198 | 2218 |
2199 current_zoom_ = new_zoom_level; | 2219 current_zoom_ = new_zoom_level; |
2200 | 2220 |
2201 CalculateVisiblePages(); | 2221 CalculateVisiblePages(); |
2202 UpdateTickMarks(); | 2222 UpdateTickMarks(); |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3881 double* height) { | 3901 double* height) { |
3882 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3902 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3883 if (!doc) | 3903 if (!doc) |
3884 return false; | 3904 return false; |
3885 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3905 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3886 FPDF_CloseDocument(doc); | 3906 FPDF_CloseDocument(doc); |
3887 return success; | 3907 return success; |
3888 } | 3908 } |
3889 | 3909 |
3890 } // namespace chrome_pdf | 3910 } // namespace chrome_pdf |
OLD | NEW |