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_MIDDLE) |
gene
2015/01/07 23:16:01
nit: could you please check (GetButton() != LEFT &
Deepak
2015/01/08 08:44:57
Done.
| |
1609 return false; | 1609 return false; |
1610 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_RIGHT) { | |
1611 if (!selection_.size()) | |
1612 return false; | |
1613 std::vector<pp::Rect> selection_rect_vector; | |
1614 GetAllScreenRectsUnion(selection_, GetVisibleRect().point(), | |
1615 &selection_rect_vector); | |
1616 pp::Point point = event.GetPosition(); | |
1617 for (size_t i = 0; i < selection_rect_vector.size(); ++i) { | |
1618 if (selection_rect_vector[i].IsEmpty() || | |
gene
2015/01/07 23:16:01
Could you please explain why you exit here if at l
Deepak
2015/01/08 08:44:57
first condition is not required so removing this.
| |
1619 selection_rect_vector[i].Contains(point.x(), point.y())) { | |
1620 return false; | |
1621 } | |
1622 } | |
1623 SelectionChangeInvalidator selection_invalidator(this); | |
1624 selection_.clear(); | |
1625 return true; | |
1626 } | |
1610 | 1627 |
1611 SelectionChangeInvalidator selection_invalidator(this); | 1628 SelectionChangeInvalidator selection_invalidator(this); |
1612 selection_.clear(); | 1629 selection_.clear(); |
1613 | 1630 |
1614 int page_index = -1; | 1631 int page_index = -1; |
1615 int char_index = -1; | 1632 int char_index = -1; |
1616 PDFiumPage::LinkTarget target; | 1633 PDFiumPage::LinkTarget target; |
1617 PDFiumPage::Area area = GetCharIndex(event, &page_index, | 1634 PDFiumPage::Area area = GetCharIndex(event, &page_index, |
1618 &char_index, &target); | 1635 &char_index, &target); |
1619 mouse_down_state_.Set(area, target); | 1636 mouse_down_state_.Set(area, target); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2171 find_results_.clear(); | 2188 find_results_.clear(); |
2172 next_page_to_search_ = -1; | 2189 next_page_to_search_ = -1; |
2173 last_page_to_search_ = -1; | 2190 last_page_to_search_ = -1; |
2174 last_character_index_to_search_ = -1; | 2191 last_character_index_to_search_ = -1; |
2175 current_find_index_.Invalidate(); | 2192 current_find_index_.Invalidate(); |
2176 current_find_text_.clear(); | 2193 current_find_text_.clear(); |
2177 UpdateTickMarks(); | 2194 UpdateTickMarks(); |
2178 find_factory_.CancelAll(); | 2195 find_factory_.CancelAll(); |
2179 } | 2196 } |
2180 | 2197 |
2198 void PDFiumEngine::GetAllScreenRectsUnion(std::vector<PDFiumRange>& rect_range, | |
2199 const pp::Point offset_point, | |
2200 std::vector<pp::Rect>* rect_vector) { | |
2201 for (size_t i = 0; i < rect_range.size(); ++i) { | |
2202 pp::Rect rect; | |
2203 std::vector<pp::Rect> rects = rect_range[i].GetScreenRects( | |
2204 offset_point, current_zoom_, current_rotation_); | |
2205 for (size_t j = 0; j < rects.size(); ++j) | |
2206 rect = rect.Union(rects[j]); | |
2207 rect_vector->push_back(rect); | |
2208 } | |
2209 } | |
2210 | |
2181 void PDFiumEngine::UpdateTickMarks() { | 2211 void PDFiumEngine::UpdateTickMarks() { |
2182 std::vector<pp::Rect> tickmarks; | 2212 std::vector<pp::Rect> tickmarks; |
2183 for (size_t i = 0; i < find_results_.size(); ++i) { | 2213 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); | 2214 client_->UpdateTickMarks(tickmarks); |
2194 } | 2215 } |
2195 | 2216 |
2196 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { | 2217 void PDFiumEngine::ZoomUpdated(double new_zoom_level) { |
2197 CancelPaints(); | 2218 CancelPaints(); |
2198 | 2219 |
2199 current_zoom_ = new_zoom_level; | 2220 current_zoom_ = new_zoom_level; |
2200 | 2221 |
2201 CalculateVisiblePages(); | 2222 CalculateVisiblePages(); |
2202 UpdateTickMarks(); | 2223 UpdateTickMarks(); |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3881 double* height) { | 3902 double* height) { |
3882 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3903 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3883 if (!doc) | 3904 if (!doc) |
3884 return false; | 3905 return false; |
3885 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3906 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3886 FPDF_CloseDocument(doc); | 3907 FPDF_CloseDocument(doc); |
3887 return success; | 3908 return success; |
3888 } | 3909 } |
3889 | 3910 |
3890 } // namespace chrome_pdf | 3911 } // namespace chrome_pdf |
OLD | NEW |