| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 3 * Copyright (C) 2007 Apple Inc. | 3 * Copyright (C) 2007 Apple Inc. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "core/page/PrintContext.h" | 21 #include "core/page/PrintContext.h" |
| 22 | 22 |
| 23 #include <utility> |
| 24 |
| 23 #include "core/frame/FrameView.h" | 25 #include "core/frame/FrameView.h" |
| 24 #include "core/frame/LocalFrame.h" | 26 #include "core/frame/LocalFrame.h" |
| 25 #include "core/layout/LayoutView.h" | 27 #include "core/layout/LayoutView.h" |
| 26 #include "core/layout/api/LayoutViewItem.h" | 28 #include "core/layout/api/LayoutViewItem.h" |
| 27 #include "platform/graphics/GraphicsContext.h" | 29 #include "platform/graphics/GraphicsContext.h" |
| 28 | 30 |
| 29 namespace blink { | 31 namespace blink { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // 13329.99 are treated as 13330 so that we don't mistakenly assign an extra | 124 // 13329.99 are treated as 13330 so that we don't mistakenly assign an extra |
| 123 // page for the stray pixel. | 125 // page for the stray pixel. |
| 124 int page_height = page_size_in_pixels.Height() + LayoutUnit::Epsilon(); | 126 int page_height = page_size_in_pixels.Height() + LayoutUnit::Epsilon(); |
| 125 | 127 |
| 126 bool is_horizontal = view.Style()->IsHorizontalWritingMode(); | 128 bool is_horizontal = view.Style()->IsHorizontalWritingMode(); |
| 127 | 129 |
| 128 int doc_logical_height = is_horizontal ? doc_rect.Height() : doc_rect.Width(); | 130 int doc_logical_height = is_horizontal ? doc_rect.Height() : doc_rect.Width(); |
| 129 int page_logical_height = is_horizontal ? page_height : page_width; | 131 int page_logical_height = is_horizontal ? page_height : page_width; |
| 130 int page_logical_width = is_horizontal ? page_width : page_height; | 132 int page_logical_width = is_horizontal ? page_width : page_height; |
| 131 | 133 |
| 132 int inline_direction_start; | 134 int inline_direction_start = doc_rect.X(); |
| 133 int inline_direction_end; | 135 int inline_direction_end = doc_rect.MaxX(); |
| 134 int block_direction_start; | 136 int block_direction_start = doc_rect.Y(); |
| 135 int block_direction_end; | 137 int block_direction_end = doc_rect.MaxY(); |
| 136 if (is_horizontal) { | 138 if (!is_horizontal) { |
| 137 if (view.Style()->IsFlippedBlocksWritingMode()) { | 139 std::swap(block_direction_start, inline_direction_start); |
| 138 block_direction_start = doc_rect.MaxY(); | 140 std::swap(block_direction_end, inline_direction_end); |
| 139 block_direction_end = doc_rect.Y(); | |
| 140 } else { | |
| 141 block_direction_start = doc_rect.Y(); | |
| 142 block_direction_end = doc_rect.MaxY(); | |
| 143 } | |
| 144 inline_direction_start = | |
| 145 view.Style()->IsLeftToRightDirection() ? doc_rect.X() : doc_rect.MaxX(); | |
| 146 inline_direction_end = | |
| 147 view.Style()->IsLeftToRightDirection() ? doc_rect.MaxX() : doc_rect.X(); | |
| 148 } else { | |
| 149 if (view.Style()->IsFlippedBlocksWritingMode()) { | |
| 150 block_direction_start = doc_rect.MaxX(); | |
| 151 block_direction_end = doc_rect.X(); | |
| 152 } else { | |
| 153 block_direction_start = doc_rect.X(); | |
| 154 block_direction_end = doc_rect.MaxX(); | |
| 155 } | |
| 156 inline_direction_start = | |
| 157 view.Style()->IsLeftToRightDirection() ? doc_rect.Y() : doc_rect.MaxY(); | |
| 158 inline_direction_end = | |
| 159 view.Style()->IsLeftToRightDirection() ? doc_rect.MaxY() : doc_rect.Y(); | |
| 160 } | 141 } |
| 142 if (!view.Style()->IsLeftToRightDirection()) |
| 143 std::swap(inline_direction_start, inline_direction_end); |
| 144 if (view.Style()->IsFlippedBlocksWritingMode()) |
| 145 std::swap(block_direction_start, block_direction_end); |
| 161 | 146 |
| 162 unsigned page_count = ceilf((float)doc_logical_height / page_logical_height); | 147 unsigned page_count = |
| 148 ceilf(static_cast<float>(doc_logical_height) / page_logical_height); |
| 163 for (unsigned i = 0; i < page_count; ++i) { | 149 for (unsigned i = 0; i < page_count; ++i) { |
| 164 int page_logical_top = | 150 int page_logical_top = |
| 165 block_direction_end > block_direction_start | 151 block_direction_end > block_direction_start |
| 166 ? block_direction_start + i * page_logical_height | 152 ? block_direction_start + i * page_logical_height |
| 167 : block_direction_start - (i + 1) * page_logical_height; | 153 : block_direction_start - (i + 1) * page_logical_height; |
| 168 | 154 |
| 169 int page_logical_left = inline_direction_end > inline_direction_start | 155 int page_logical_left = inline_direction_end > inline_direction_start |
| 170 ? inline_direction_start | 156 ? inline_direction_start |
| 171 : inline_direction_start - page_logical_width; | 157 : inline_direction_start - page_logical_width; |
| 172 IntRect page_rect(page_logical_left, page_logical_top, page_logical_width, | 158 IntRect page_rect(page_logical_left, page_logical_top, page_logical_width, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 350 } |
| 365 | 351 |
| 366 ScopedPrintContext::ScopedPrintContext(LocalFrame* frame) | 352 ScopedPrintContext::ScopedPrintContext(LocalFrame* frame) |
| 367 : context_(new PrintContext(frame)) {} | 353 : context_(new PrintContext(frame)) {} |
| 368 | 354 |
| 369 ScopedPrintContext::~ScopedPrintContext() { | 355 ScopedPrintContext::~ScopedPrintContext() { |
| 370 context_->EndPrintMode(); | 356 context_->EndPrintMode(); |
| 371 } | 357 } |
| 372 | 358 |
| 373 } // namespace blink | 359 } // namespace blink |
| OLD | NEW |