| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.res.TypedArray; | 8 import android.content.res.TypedArray; |
| 9 import android.util.TypedValue; | 9 import android.util.TypedValue; |
| 10 import android.view.Gravity; | 10 import android.view.Gravity; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 public void onClick(View v) { | 104 public void onClick(View v) { |
| 105 paste(); | 105 paste(); |
| 106 hide(); | 106 hide(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 private void positionAt(int x, int y) { | 109 private void positionAt(int x, int y) { |
| 110 if (mRawPositionX == x && mRawPositionY == y && isShowing()) return; | 110 if (mRawPositionX == x && mRawPositionY == y && isShowing()) return; |
| 111 mRawPositionX = x; | 111 mRawPositionX = x; |
| 112 mRawPositionY = y; | 112 mRawPositionY = y; |
| 113 | 113 |
| 114 View contentView = mContainer.getContentView(); | 114 final View contentView = mContainer.getContentView(); |
| 115 int width = contentView.getMeasuredWidth(); | 115 final int width = contentView.getMeasuredWidth(); |
| 116 int height = contentView.getMeasuredHeight(); | 116 final int height = contentView.getMeasuredHeight(); |
| 117 | 117 |
| 118 mPositionX = (int) (x - width / 2.0f); | 118 mPositionX = (int) (x - width / 2.0f); |
| 119 mPositionY = y - height - mLineOffsetY; | 119 mPositionY = y - height - mLineOffsetY; |
| 120 | 120 |
| 121 final int[] coords = new int[2]; | 121 final int[] coords = new int[2]; |
| 122 mParent.getLocationInWindow(coords); | 122 mParent.getLocationInWindow(coords); |
| 123 coords[0] += mPositionX; | 123 coords[0] += mPositionX; |
| 124 coords[1] += mPositionY; | 124 coords[1] += mPositionY; |
| 125 | 125 |
| 126 int minOffsetY = 0; | 126 int minOffsetY = 0; |
| 127 if (mParent.getSystemUiVisibility() == View.SYSTEM_UI_FLAG_VISIBLE) { | 127 if (mParent.getSystemUiVisibility() == View.SYSTEM_UI_FLAG_VISIBLE) { |
| 128 minOffsetY = mStatusBarHeight; | 128 minOffsetY = mStatusBarHeight; |
| 129 } | 129 } |
| 130 | 130 |
| 131 final int screenWidth = mContext.getResources().getDisplayMetrics().widt
hPixels; | 131 final int screenWidth = mContext.getResources().getDisplayMetrics().widt
hPixels; |
| 132 if (coords[1] < minOffsetY) { | 132 if (coords[1] < minOffsetY) { |
| 133 // Update dimensions from new view | |
| 134 contentView = mContainer.getContentView(); | |
| 135 width = contentView.getMeasuredWidth(); | |
| 136 height = contentView.getMeasuredHeight(); | |
| 137 | |
| 138 // Vertical clipping, move under edited line and to the side of inse
rtion cursor | 133 // Vertical clipping, move under edited line and to the side of inse
rtion cursor |
| 139 // TODO bottom clipping in case there is no system bar | 134 // TODO bottom clipping in case there is no system bar |
| 140 coords[1] += height; | 135 coords[1] += height; |
| 141 coords[1] += mLineOffsetY; | 136 coords[1] += mLineOffsetY; |
| 142 | 137 |
| 143 // Move to right hand side of insertion cursor by default. TODO RTL
text. | 138 // Move to right hand side of insertion cursor by default. TODO RTL
text. |
| 144 final int handleHalfWidth = mWidthOffsetX / 2; | 139 final int handleHalfWidth = mWidthOffsetX / 2; |
| 145 | 140 |
| 146 if (x + width < screenWidth) { | 141 if (x + width < screenWidth) { |
| 147 coords[0] += handleHalfWidth + width / 2; | 142 coords[0] += handleHalfWidth + width / 2; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 mPasteView.setOnClickListener(this); | 178 mPasteView.setOnClickListener(this); |
| 184 } | 179 } |
| 185 | 180 |
| 186 mContainer.setContentView(mPasteView); | 181 mContainer.setContentView(mPasteView); |
| 187 } | 182 } |
| 188 | 183 |
| 189 private void paste() { | 184 private void paste() { |
| 190 mDelegate.paste(); | 185 mDelegate.paste(); |
| 191 } | 186 } |
| 192 } | 187 } |
| OLD | NEW |